`

oracle查询当天,一星期,当月的数据【转】

 
阅读更多
写道
当天的

Select * From my_table a Where trunc(create_date)

= trunc(Sysdate);


当月的

Select * From my_table a Where to_char(create_date,'yyyymm')

= to_char(Sysdate,'yyyymm');

 
当星期的

trunc(Sysdate,'d')这是这个星期的第一天。

Next_day(trunc(sysdate,'d'),7) 这是这个星期的最后一天。

Select * From my_table a Where trunc(create_date)>=trunc(Sysdate,'d')

AND trunc(create_date)<= Next_day(trunc(sysdate,'d'),7)
 


当月的数据

select * from CDD_SITE t

where t.add_time >=TRUNC(SYSDATE, 'MM')

and t.add_time<=last_day(SYSDATE)

 
当年的数据

select * from CDD_SITE t

where t.ADD_TIME >=trunc(sysdate,'YYYY')

and t.ADD_TIME<=add_months(trunc(sysdate,'YYYY'),12)-1
 

查当年的数据,并且按月份分组

select count(*) from CDD_SITE site where 1 = 1 and site.ADD_TIME >=trunc(sysdate,'YYYY')

and site.ADD_TIME<=add_months(trunc(sysdate,'YYYY'),12)-1

group by TO_CHAR(site.add_time,'MM') ORDER BY TO_CHAR(site.add_time,'MM') asc

 FROM:http://my.csdn.net/xuetan121/code/detail/28019

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics