SQL搜索列中相同的项

来源:百度知道 编辑:UC知道 时间:2024/09/24 07:21:59
表A 其中有列B 列B=1,2,3,4,5,6,7,2,3,4,6等.

如何查询出 列B的数值不是唯一的所有行。
如2,3,4,6都各有两行.如何用语句搜索出来
你们现在搜索出来的是B=2,3,4,6
我要查询出来的东西格式是select * from A where B=2 or B=3 or B=4 or B=6 (假定我知道2,3,4,6是有重复的)
(现在我是不知道2,3,4,6有重复,要用查询把它一并查出来)

select 列B
from 表A
group by 列B
having count(列B) > 1

这里用到group by子句将“列B”中的数据分组,然后用个having子句过滤出数据为两条以上的字段。这样就可以查询出你要的结果了。

select B from A group by B having count(1)>1

select b,count(b)
from a
group by b
having count(b) > 1

select * from A where B in(select B from A group by B having count(1)>1 )