表结构如下
ID ZiMu Shuzi
1 A 1
2 B 1
3 C 1
4 A 2
5 B 2
6 C 2
7 A 3
8 B 3
9 C 3
要求查询到以下结果
ID ZiMu Shuzi
1 A 1
4 A 2
7 A 3
------解决方案--------------------
- SQL code
declare @t table (ID int,ZiMu varchar(1),Shuzi int)insert into @tselect 1,'A',1 union allselect 2,'B',1 union allselect 3,'C',1 union allselect 4,'A',2 union allselect 5,'B',2 union allselect 6,'C',2 union allselect 7,'A',3 union allselect 8,'B',3 union allselect 9,'C',3select * from @t t where ID=(select min(ID) from @t where Shuzi=t.Shuzi)/*ID ZiMu Shuzi----------- ---- -----------1 A 14 A 27 A 3*/