阅读419 返回首页    go 阿里云 go 技术社区[云栖]


oracle 查询本周,本月,本年数据

当月数据

Java代码
  1. select * from table t       
  2. where t.create_time >=TRUNC(SYSDATE, 'MM')       
  3. and t.create_time<=last_day(SYSDATE)    
select * from table t where t.create_time >=TRUNC(SYSDATE, 'MM') and t.create_time<=last_day(SYSDATE)Java代码
  1. create_time为你要查询的时间  
create_time为你要查询的时间

当年数据

Java代码
  1. select * from table t      
  2. where t.create_time >=trunc(sysdate,'YYYY')       
  3. and t.create_time<=add_months(trunc(sysdate,'YYYY'),12)-1  
select * from table t where t.create_time >=trunc(sysdate,'YYYY') and t.create_time<=add_months(trunc(sysdate,'YYYY'),12)-1

本周(国外周日为一个星期第一天)

Java代码
  1. where t.create_time >=trunc(sysdate,'day')+1 and t.create_time<=trunc(sysdate,'day')+6    
where t.create_time >=trunc(sysdate,'day')+1 and t.create_time<=trunc(sysdate,'day')+6

本周(国内周一为一个星期第一天)

Java代码
  1. where t.create_time >=trunc(next_day(sysdate-8,1)+1) and t.create_time<=trunc(next_day(sysdate-8,1)+7)+1  
where t.create_time >=trunc(next_day(sysdate-8,1)+1) and t.create_time<=trunc(next_day(sysdate-8,1)+7)+1

  

最后更新:2017-04-03 14:53:55

  上一篇:go MySQL JDBC 5.1.25的一个坑(应该算是BUG)
  下一篇:go Android 多分辨率屏显设计及其兼容性测试