已知这样一个集合
id value
1 550
1 552
1 554
7 550
7 551
7 552
3117 550
3117 558
3117 559结果
id value
1 550
7 550
3117 550每个 ID 只取第一个 value
id value
1 550
1 552
1 554
7 550
7 551
7 552
3117 550
3117 558
3117 559结果
id value
1 550
7 550
3117 550每个 ID 只取第一个 value
drop table tb
go
create table tb(id int,value int)
insert into tb values(1,550)
insert into tb values(1,552)
insert into tb values(1,554)
insert into tb values(7,550)
insert into tb values(7,558)
insert into tb values(7,559)insert into tb values(3117,550)
insert into tb values(3117,558)
insert into tb values(3117,559)
select id,MIN(value) from tb group by id
id value
----------- -----------
1 550
7 550
3117 550(3 行受影响)