--> 测试数据: [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一个问题发一遍即可
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一个问题发一遍即可
select distinct top 8 dd from [table]
order by dd
我想获取前8个分组所有值呢,而不是distinct
这么写的话是 a1a1b1c1c1c1d1d1 总共8条记录 而不是8个分组的记录,像这样a1a1a1.......
b1b1b1b1..................
c1c1...............
d1d1d1...............
e1e1...............
s1s1............
h1h1.............
i1..............