SQL表列如下:单号               日期
1               2011-09-10
2               2011-09-10
.               ......
.               ......
.               ......
如何显示每天的前10行记录,谢

解决方案 »

  1.   

    select
      distinct b.* 
    from
      tb a
    cross apply
      (select top 10 * from tb where convert(varchar(10),日期,120)=convert(varchar(10),t.日期,120))b
      

  2.   

    select b.* from tb a
    cross apply(select top 10 * from tb where 日期=a.日期) b
      

  3.   

    select * from tb a where 单号 in(select top 10 单号 from tb where 日期=a.日期 order by 单号)
      

  4.   

    select * from (
    select *,rank () over(partition by day(日期) order by 日期) rk from tb
    ) t
    where t.rk<=10
      

  5.   

    select * from tb a where 单号 in (select top 10 单号 from tb where 日期=a.日期 order by 单号)