这样写:
sqlstr="select count(*) as num from tab where trunc(inputtime) = trunc(ADD_MONTHS(sysDate,-1))";
不对诶,结果总是0
到底应该是怎么样的呢?

解决方案 »

  1.   

    你取的是30天内的数据,但你的写法却好象只能够检索出一天的数据,你看看下面的写法可以不:
    sqlstr="select count(*) as num from tab where trunc(inputtime) > trunc(ADD_MONTHS(sysDate,-1))";
      

  2.   

    sqlstr="select count(*) num from tab where trunc(inputtime) >= trunc(ADD_MONTHS(sysDate,-1))";
      

  3.   

    sqlstr="select count(*) num from tab where trunc(inputtime) >= trunc(ADD_MONTHS(sysDate,-1))";对了、非常的感谢hp_oracle(刚学)、xinpingf(白开心) !
    还是有点小问题:
    这里的ADD_MONTHS 是月份吧,我把它改为ADD_DAYS不行吗?因为我要的是多少天内的记录,比如说N天内,想-N 这个-N天的写法是怎么样的?