select [DateTime],num=isnull((select count(*) from 表 where [DateTime]<a.[DateTime]),0)
from(select distinct [DateTime]=convert(char(10),[DateTime],120) from 表)a

解决方案 »

  1.   

    select covnert(varchar(10),[DateTime],120)
    ,num=sum(select 1 form tb b where where b.datetime<a.datetime
    from tb a group by covnert(varchar(10),[DateTime],120)
      

  2.   

    select a.DateTime,[count]=(select count(*) from 表 where a.DateTime=Datetime) from 表 group by a.DateTime