`

to_date() 时间相减 截取

 
阅读更多

to_date() 时间相减

select to_date(untreat_date,'yyyy-mm-dd hh24:mi:ss')-to_date(reg_date,'yyyy-mm-dd hh24:mi:ss')
  from XXX where to_date(untreat_date,'yyyy-mm-dd hh24:mi:ss')-to_date(reg_date,'yyyy-mm-dd hh24:mi:ss')>0

 

TRUNC(date[,fmt]) 截取

      date 一个日期值 
  fmt 日期格式,该日期将由指定的元素格式所截去。忽略它则由最近的日期截去

      trunc(sysdate,'yyyy') --返回当年第一天. 
  trunc(sysdate,'mm') --返回当月第一天.
  trunc(sysdate,'d') --返回当前星期的第一天.
  trunc(sysdate,'dd')--返回当前年月日

 

select status,count(*) countnum,CAST(sum(time) as decimal(38, 0))
sumtime from XXX where indate>trunc(sysdate-2)
AND indate<trunc(sysdate) group by status

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics