当前位置: 代码迷 >> Sql Server >> 初学者有关问题,等!
  详细解决方案

初学者有关问题,等!

热度:221   发布时间:2016-04-27 19:22:05.0
菜鸟问题,急等!!!
我想查一些数据,比如说:
A B
1 a
2 b
2 c
3 d
4 d
5 d
5 c
我想找出所有A字段中对应B字段属性不唯一的值,怎么写语句啊


------解决方案--------------------
是不是A字段对应多个B字段的意思?

select A from [tableName] group by A having count(b) > 1
------解决方案--------------------
SQL code
同意楼上select A from [tableName] group by A having count(1) > 1
------解决方案--------------------
楼上正解
A,B字段没有重复的吧?
------解决方案--------------------
SQL code
create table tb(A int ,  B  varchar(10))insert into tb select 1,  'a' insert into tb select 2 , 'b' insert into tb select 2 , 'c' insert into tb select 3 , 'd'insert into tb select 4 , 'd' insert into tb select 5 , 'd' insert into tb select 5 , 'c' select * from tb where a in (select A from tb group by A having count(b) > 1)
------解决方案--------------------
select * from t
where A in (select A from t group by A having count(1)>1)
  相关解决方案