一张业务表 有个日期字段:appCreateDate ,现在求一条sql语句;根据系统时间与appCreateDate 字段比较实现以下统计:
今日申请单数 ,最近7天申请单数,最近30天申请单数,另,我的系统表中数据是:2010-9-7,而to_char(sysdate,'YYYY-MM-DD')后的日期是2010-09-7,这个怎么比较,请高手指点,在线等.....

解决方案 »

  1.   

    三种统计UNION 
    至于时间的话,不能直接转换的话,就要自己写个函数去解析这个字符串获得正确的日期
      

  2.   


    select 
    count(case when to_date(appCreateDate,'yyyy-mm-dd') > trunc(sysdate) then 1 end ) d1
    ,count(case when to_date(appCreateDate,'yyyy-mm-dd') > trunc(sysdate-7) then 1 end ) d7
    ,count(*) d30from 业务表
    where to_date(appCreateDate,'yyyy-mm-dd') > trunc(sysdate-30)