日:
select count(1)
from student_bill where 1=1
and sub_merchant_id = #
and to_char(pay_time,'yyyy-mm-dd')= to_char(to_date(#, 'yyyy-mm-dd hh24:mi:ss')-#,'yyyy-mm-dd') and status = '1'
and to_char(pay_time,'yyyy-mm-dd')= to_char(to_date(#, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd') and status = '1'
周:
select count(1)
from student_bill where 1=1
and sub_merchant_id = #
and pay_time between trunc(next_day(to_date(#, 'yyyy-mm-dd hh24:mi:ss') - 1, 1)-6) and trunc(next_day(to_date(#, 'yyyy-mm-dd hh24:mi:ss') - 1, 1)+1) and status = '1'
and pay_time between trunc(next_day(to_date(#, 'yyyy-mm-dd hh24:mi:ss') -(1+#*7), 1)-6) and trunc(next_day(to_date(#, 'yyyy-mm-dd hh24:mi:ss') - (1+#*7), 1)+1) and status = '1'
月:
select count(1)
from student_bill where 1=1
and sub_merchant_id = #
and to_char(pay_time,'yyyy-mm')= to_char(add_months(to_date(#, 'yyyy-mm-dd hh24:mi:ss'),0),'yyyy-mm') and status = '1'
and to_char(pay_time,'yyyy-mm')= to_char(add_months(to_date(#, 'yyyy-mm-dd hh24:mi:ss'),-#),'yyyy-mm') and status = '1'
備註:type的值 :0表示當日,1表示昨天,依次往前,想獲取幾天一次增加type的值
周和月一樣,0表示當月當周,1表示上一月上一周等
周的時間是:周一到週日的交易區間
日期具體獲取方式:
//周
select next_day(to_date('2018-8-3','yyyy-mm-dd'),1) from dual;//找到下一周的第一天,也就是日曆中的下一周星期日
select next_day(to_date('2018-8-3','yyyy-mm-dd')-8,1) from dual;//找到本週的週日,本週的第一天
select trunc(next_day(to_date('2018-8-3','yyyy-mm-dd')-1,1)-6) from dual;//找到本週的星期一,本週的第二天
select trunc(next_day(to_date('2018-8-3','yyyy-mm-dd')-1,1)+1) from dual;//找到下一周的星期一,下週的第二天
select trunc(next_day(to_date('2018-8-3','yyyy-mm-dd')-8,1)-6) from dual;//找到上週的星期一,上週的第二天
//所以區間為本周一的00:00:00到下周一的00:00:00,而不是到下周天的23:59:59
//日select to_char(to_date('2018-8-3', 'yyyy-mm-dd hh24:mi:ss')-3,'yyyy-mm-dd') from dual;//獲取當前日期減去幾就是從今天起往前推幾天
//月select to_char(add_months(to_date('2018-8-3', 'yyyy-mm-dd hh24:mi:ss'),-2),'yyyy-mm') from dual;//獲取當前月,再傳入負幾就是從這月起往前推幾月
根據當前時間獲取本週,下週,上週日期
實現點選按鈕更改周,並獲取本週,上週,下週對應的具體日期 借鑑了一些網上的方法 定義 datetime begindate getweekupofdate datetime.now,dayofweek.monday,0 預設開始時間為本週周一 datetime enddate getweekupof...
oracle 當前時間列表
2.當月所有 當前年所有日期sql語句 select trunc sysdate,yyyy rownum 1 as all year date from dual connect by rownum 365 當前月所有日期sql語句 寫法 select level,to char trunc to ...
oracle獲取當前時間
select to char sysdate,yyyy mm dd hh24 mi ss from dual select to char sysdate,yyyy mm dd hh24 mm ss from dual 容易出錯 elect to char sysdate,yyyy mm dd hh...