>>主要是 与现在的日期相比 得到超出 3 个月的 不知道到怎么写呀
where datediff(mm,c,getdate())>3

解决方案 »

  1.   

    select 
        m.a,m.b,n.c
    from
        table1 m
    inner join
        (select b,max(c) c from table2 group by b) n  
    where 
        datediff(month,n.c,getdate()) > (case when day(n.c)>day(getdate()) then 4 else 3 end)
      

  2.   

    dateadd(month,-3,getdate())>cdateadd(day,-90,getdate())>c
      

  3.   

    修改一下:select 
        m.a,m.b,n.c
    from
        table1 m
    inner join
        (select b,max(c) c from table2 group by b) n  
    where 
        datediff(month,n.c,getdate()) > (case when day(n.c)>day(getdate()) then 3 else 2 end)
      

  4.   

    Select A.b,A.c,table1.e from table2  A Inner Join table1 On table1.b=A.b Where A.C>DateAdd(m,3,GetDate()) And 
    A.C=(Select C from table2 Where a=A.a) 
      

  5.   

    加上  where datediff(d,dateadd(month,3,@date),getdate())>0  即可这里@date就是你要判断的时间字段
      

  6.   

    select *
    from table1 a,table2 b
    where a.b=b.b
    and b.c<dateadd(month,-3,getdate())  --日期限制
    and not exists(                      --去重复处理
    select * from table2
    where b=b.b
    and b.c<dateadd(month,-3,getdate())
    and c>b.c)
      

  7.   

    上述写法的好处是把计算工作转到右边,这样table2.c字段上有索引的话,可以充分利用索引实现高效处理另外,上述方法得到的记录是精确的三个月,避免了datediff方法会出现按天数比较不足3个月的问题
      

  8.   

    select * from table1 f where f.b=e.b
    (select e.a,  
    from talbe2 e
    group by e.b  
    having (DATEADD(month, 3, max(e.c))) < getdate() )