我想要一个查询来计算列中的重复值,是否有任何查询,或者我认为是
total records=SELECT COUNT(column_name) FROM table_name;
distinct records=SELECT COUNT(DISTINCT column_name) FROM table_name;
duplicate count=total records-distinct records;
答案 0 :(得分:2)
查看你的sql,它可以简化如下:
SELECT Count(Column) - Count(DISTINCT Column)
FROM yourTable
答案 1 :(得分:1)
差不多,是的。您可以在一个查询中执行此操作:
SELECT (SELECT COUNT(col) FROM tbl) - (SELECT COUNT(DISTINCT col) FROM tbl);
编辑:NoDisplayName的好点。这至少适用于MySQL,我不保证跨引擎的兼容性(我上次在十五年前在Oracle上工作过,而且从不在SQL Server上工作)
答案 2 :(得分:1)
select column_name, count(*)
from table_name
group by column_name
having count(*) > 1
答案 3 :(得分:0)
你可以试试这个:
SELECT COUNT(column_name) as count
FROM table_name
GROUP BY column_name
HAVING count > 1