c1 c2 type
第1行 a 9 5
第2行 b 8 5
第3行 c 7 6
第4行 d 6 6
第5行 e 5 7
--@Test
declare @test table(c1 varchar(1),c2 int,type int)
insert @test
select 'a',9,5 union all
select 'b',8,5 union all
select 'c',7,6 union all
select 'd',6,6 union all
select 'e',5,7
--按记录顺序取第一条
select * from @test a where c1=(select top 1 c1 from @Test where type=a.type)
--取最小
select * from @test a where c1=(select min(c1) from @Test where type=a.type)
--取最大
select * from @test a where c1=(select max(c1) from @Test where type=a.type)
--随机取
select * from @test a where c1=(select top 1 c1 from @Test where type=a.type order by newid())