select * from tb where datediff(mm,getdate(),b)=0 group by a having count(a)>2

解决方案 »

  1.   

    select a from 表 where Convert(varchar(7),b,120)='2006-01' group by a having count(*)>1
      

  2.   

    楼主说的条件:在一个月内 不知道是指:与今日相差一个月以内(即我写的那样)
    还是指具体某个月里面!
    如果是第二种,where 条件改一下就可以了
      

  3.   

    declare @month int
    set @month=1
    select a from 表 where month(b)=@month group by a having count(*)>1
      

  4.   

    declare @month varchar(7)
    set @month='2006-01'
    select a from 表 where convert(varchar(7),[date],120)=@month group by a having count(*)>1
      

  5.   

    用了group by 好像不能用select * 的
      

  6.   

    假设表名为test,主键为id;
    select A.* from test as A ,test as B where A.a=B.a and A.ID<>B.ID and datediff(day,A.b,B.b)<=30 and datediff(day,A.b,B.b)>=-30
      

  7.   

    select A.* from test as A  where exsit (select 1 from test as B whereA.a=B.a and A.ID<>B.ID and datediff(day,A.b,B.b)<=30 and datediff(day,A.b,B.b)>=-30)