日期:2014-05-17 浏览次数:20567 次
if object_id('[A]') is not null drop table [A]
go
create table [A]([数据ID] int,[学生ID] varchar(3),[电话号码] int,[班级] sql_variant,[班主任] sql_variant)
insert [A]
select 1,'035',8785465,null,null union all
select 2,'035',8865453,null,null union all
select 3,'186',8888888,null,null union all
select 4,'186',null,null,null union all
select 5,'033',7654832,null,null union all
select 6,'042',8888888,null,null union all
select 7,'033',8324231,null,null union all
select 8,'012',8357623,null,null union all
select 9,'039',9999999,null,null union all
select 10,'177',null,null,null union all
select 11,'027',9999999,null,null union all
select 12,'027',null,null,null
go
select A.数据ID,A.学生ID,A.电话号码
from A
JOIN (SELECT 电话号码 FROM A GROUP BY 电话号码 HAVING COUNT(1)>1) B
ON A.电话号码=B.电话号码
/*
数据ID 学生ID 电话号码
----------- ---- -----------
3 186 8888888
6 042 8888888
9 039 9999999
11 &nb