我需要编写一个查询,该查询将查找具有2个或更多相同名称的所有行。我写的如下:
SELECT name
FROM (
SELECT name, COUNT(*) as count
FROM partner.propertie
GROUP BY name) as t
WHERE t.count > 1;
但我不确定这是否是最佳方式。我有很大的桌子......
答案 0 :(得分:4)
HAVING
就是你想要的:
SELECT name
FROM partner.propertie
GROUP BY name
HAVING COUNT(*) > 1
答案 1 :(得分:1)
你可以试试这个:
select * from (
SELECT name,
ROW_NUMBER() OVER(PARTITION BY name ORDER BY name asc) AS Row
FROM partner.propertie
) dups
where
dups.Row > 1
<强> SQL FIDDLE DEMO 强>