select * from 表 where datediff(dd,starttime,getdate()) in(50,60,70,75)

解决方案 »

  1.   

    不对的,有相同的htid的,要求每一个htid 的starttime距离今天50,60,70,75的记录数目前面有个地方写错了,htid不是主键,是外键
      

  2.   

    >>要求每一个htid 这个不就是每个吗
      

  3.   

    select htid,
    [50天]=sum(case when datediff(dd,starttime,getdate()) =50 then 1 else 0 end),
    [60天]=sum(case when datediff(dd,starttime,getdate()) =60 then 1 else 0 end),
    [70天]=sum(case when datediff(dd,starttime,getdate()) =70 then 1 else 0 end),
    [75天]=sum(case when datediff(dd,starttime,getdate()) =75 then 1 else 0 end),
    from test group by htid
      

  4.   

    select htid,datediff(dd,starttime,getdate()) as 'days',count(*) as 'cnt' from 表 where datediff(dd,starttime,getdate()) in(50,60,70,75)
    group by htid,datediff(dd,starttime,getdate())
      

  5.   

    lxd99423(苹果)和我想要的最接近,好结铁