[英]SQL to retrieve only duplicated values for a certain key
I have a table in Postgres as below :我在 Postgres 中有一张表,如下所示:
Key Value
1234 QAB009
1234 QAB009
1234 QAB010
1235 QAB011
1236 QAB012
1236 QAB012
1236 QAB013
I want output something similar to this , only values which are repeated more than once for a certain key我想输出类似的东西,只有对某个键重复多次的值
Key Value
1234 QAB009
1236 QAB012
Appreciate any help!感谢任何帮助!
Simply GROUP
over the criteria you consider as duplicates and use HAVING
to filter for groups with more than one row.只需对您认为重复的条件进行
GROUP
,然后使用HAVING
过滤具有多行的组。
SELECT *
FROM tbl
GROUP BY Key, Value
HAVING COUNT(Key) > 1
You can use simple aggregation with a having filter:您可以使用带有过滤器的简单聚合:
select key, value
from t
group by key, value
having Count(*) > 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.