--下面是数据测试--测试数据 declare @表A table(A varchar(10),B varchar(10)) insert into @表A select 'A','B' union all select 'B','B' union all select 'C','B' union all select 'D','F' union all select 'G','H'--查询 select A=min(a),B from @表a group by B/*--测试结果A B ---------- ---------- A B D F G H(所影响的行数为 3 行) --*/
--如果对于同一个身份证号(B),A字段的值不会重复,也可以用下面的语句,这样,即使表中还有其他字段,也可以得到正确的结果:select * from 表a a where A=(select top 1 A from 表a where B=a.B)
可以用这个语句实现: select A=min(a),B from 表 group by B
select disinict 人名,身份证号 from 表名 关键是这个参数:disinict 你查查书
declare @表A table(A varchar(10),B varchar(10))
insert into @表A
select 'A','B'
union all select 'B','B'
union all select 'C','B'
union all select 'D','F'
union all select 'G','H'--查询
select A=min(a),B from @表a group by B/*--测试结果A B
---------- ----------
A B
D F
G H(所影响的行数为 3 行)
--*/
where A=(select top 1 A from 表a where B=a.B)
select A=min(a),B
from 表
group by B