查询表中不同类型纪录,要求只要显示每种类型的其中的前几条或着中间几条????

解决方案 »

  1.   

    Try,查询每种类型的前两条记录Select * From 表 As A Where ID In (Select Top 2 ID From 表 Where 类型=A.类型 Order By ID)
      

  2.   


    set rowcount 第N条
    select * from table where type='你的类型'
    set rowcount 0
      

  3.   

    修改--存储类型
    select distinct staff_name into #t from B
    declare @count int
    set @count =1
    while @count<=(select count(*) from #t)
    begin
    --输出固定类型的第几条
    select top 1 [staff_name] from #t where staff_name not in (select top (@count) * from #t)
    set @count=@count+1
    end 
    --删除用例
    drop table #t
      

  4.   

    写错了,还要修改--存储类型
    select distinct staff_name into #t from B
    declare @count int
    set @count =1
    while @count<=(select count(*) from #t)
    begin
    --输出每种类型的第几条
    select top 1 * from B where staff_name not in (select top (@count) * from #t)
    set @count=@count+1
    end 
    --删除用例
    drop table #t