id         Name       CheckDate 
1             a               2009-1-1 
2             a               2009-2-3 
3             b               2009-1-10 
我要找出一个月以前的所有记录,应该怎么写SQL语句?

解决方案 »

  1.   

    把时间字段用函数转化成YYMM或YYYYMM格式.就知道了月份,再去找一个月前的记录就不难了。
    或者直接判断时间的大小select * from tablename where to_char(checkdate,'yyyy-mm-dd') >'需要比较的时间(yyyy-mm-dd)'
      

  2.   

    select * from 表名 where to_char(checkDate,'yyyy-mm') = to_char(to_date(to_char(sysdate,'yyyy-mm'),'yyyy-mm') -1,'yyyy-mm')我试验过了,可以执行的
      

  3.   

    select * from YOURTABLE where to_char(to_date(CheckDate ,'yyyy-mm-dd'),'yyyy-mm-dd')>= to_char(add_months(sysdate,-1),'yyyy-mm-dd');
    试一下!
      

  4.   


    select * from table where checkdate < trunc(sysdate, 'mm') and checkdate > trunc(add_months(sysdate, -1), 'mm')
      

  5.   

    select * from table t
    where t.CheckDate < ADD_MONTHS(to_date(to_char(sysdate,'dd/mm/yyyy'),'dd/mm/yyyy'), -1)