sql字段唯一查询解决办法

sql字段唯一查询表结构如下ID    ZiMu   Shuzi1    A     12    B     13    C     14    A     25    B  

sql字段唯一查询
表结构如下
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*/