--> 测试数据: [ta]
if object_id('[ta]') is not null drop table [ta]
 go
 create table [ta] ([a1] varchar(2))
insert into [ta]
select 'b1' union all
select 'x1' union all
select 'f1' union all
select 'e1' union all
select 'q1' union all
select 'm1' union all
select 's1' union all
select 'a1' union all
select 's1' union all
select 'f1' union all
select 'x1';with
wang1 as (select distinct a1 from ta),
wang2 as (select top 8 a1 from wang1)
select ta.a1
from ta join wang2 on ta.a1=wang2.a1一个问题发一遍即可

解决方案 »

  1.   

    能用main 表 dd列举个例子吗
      

  2.   

    select top 8 a1 from ta  group by a1不是很理解,是排序后再进行分组吗?group by 本身会有默认排序的吧
      

  3.   


    select distinct top 8 dd  from [table]
    order by dd 
      

  4.   


    我想获取前8个分组所有值呢,而不是distinct
      

  5.   

    select top 8 * from (select distinct(dd)dd from main)t order by dd
      

  6.   


    这么写的话是 a1a1b1c1c1c1d1d1  总共8条记录 而不是8个分组的记录,像这样a1a1a1.......
    b1b1b1b1..................
    c1c1...............
    d1d1d1...............
    e1e1...............
    s1s1............
    h1h1.............
    i1..............