22,207
社区成员
发帖
与我相关
我的任务
分享
create table tb(a int, b varchar(10),c int)
insert into tb values(1 ,'b1',null)
insert into tb values(2 ,'b2',null)
insert into tb values(3 ,'b1',null)
insert into tb values(4 ,'b3',null)
insert into tb values(5 ,'b4',null)
insert into tb values(6 ,'b2',null)
go
select m.* from tb m,
(select * from tb t where a = (select min(a) from tb where b = t.b)) n
where m.b = n.b
order by n.a
drop table tb
/*
a b c
----------- ---------- -----------
1 b1 NULL
3 b1 NULL
2 b2 NULL
6 b2 NULL
4 b3 NULL
5 b4 NULL
(所影响的行数为 6 行)
*/
select m.* from tb m,
(select * from tb t where a = (select min(a) from tb where b = t.b)) n
where m.b = n.b
order by n.a
select * from tb order by b,a
select * from tb order by b , a