8 个解决方案
#1
select distinct phone,address from [表]
select phone,address from group by phone,address
#2
select distinct phone,address from [表]
select phone,address from [表] group by phone,address
#3
select * from TB T Where not exists (select 1 from T.phone=phone And T.address =address And T.[ID]>[ID])
--假设ID为主键
#4
1.如果只是显示这两个phone,address,比较简单,
select distinct phone,address from tablename
select phone,address from tablename group by phone,address
2.如果显示五个字段,则要先取出相同phone,address中,id最大或者最小的一个即可
select * from tablename T Where exists (select 1 from (select max(id) as id from tablename group by phone,address) z where z.id=t.id)
--假设ID为主键
#5
--楼主的意思是重复出现一条数据,不重复的也查询出来
select distinct phone,address from tablename--只要phone,address这两条数据的话
alter tab add colunm id indetity(int)
select * from tab a Where exists (select 1 from (select max(id) as id from tablename group by phone,address) b where a.id=b.id)
#6
楼上的,现在都是查询出来重复的数据信息,并没有把不重复的查询出来,而且重复相同的只取其中的一条。也就是说重复相同的数据只取一条,不重复的也取出来
#7
--有重复
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)>1 and sum(address)>1
--无重复
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)=1 and sum(address)=1
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)>1 and sum(address)>1
--无重复
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)=1 and sum(address)=1
#8
中间用union拼接
#1
select distinct phone,address from [表]
select phone,address from group by phone,address
#2
select distinct phone,address from [表]
select phone,address from [表] group by phone,address
#3
select * from TB T Where not exists (select 1 from T.phone=phone And T.address =address And T.[ID]>[ID])
--假设ID为主键
#4
1.如果只是显示这两个phone,address,比较简单,
select distinct phone,address from tablename
select phone,address from tablename group by phone,address
2.如果显示五个字段,则要先取出相同phone,address中,id最大或者最小的一个即可
select * from tablename T Where exists (select 1 from (select max(id) as id from tablename group by phone,address) z where z.id=t.id)
--假设ID为主键
#5
--楼主的意思是重复出现一条数据,不重复的也查询出来
select distinct phone,address from tablename--只要phone,address这两条数据的话
alter tab add colunm id indetity(int)
select * from tab a Where exists (select 1 from (select max(id) as id from tablename group by phone,address) b where a.id=b.id)
#6
楼上的,现在都是查询出来重复的数据信息,并没有把不重复的查询出来,而且重复相同的只取其中的一条。也就是说重复相同的数据只取一条,不重复的也取出来
#7
--有重复
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)>1 and sum(address)>1
--无重复
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)=1 and sum(address)=1
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)>1 and sum(address)>1
--无重复
select 其他字段,sum(phone),sum(address) from 表
group by 其他字段
having sum(phone)=1 and sum(address)=1
#8
中间用union拼接