【发布时间】:2019-05-21 22:37:20
【问题描述】:
我正在使用 Snowflake 数据库并运行此查询来查找总计数、不同记录的数量和差异:
select
(select count(*) from mytable) as total_count,
(select count(*) from (select distinct * from mytable)) as distinct_count,
(select count(*) from mytable) - (select count(*) from (select distinct * from mytable)) as duplicate_count
from mytable limit 1;
结果:
1,759,867
1,738,924
20,943 (duplicate_count)
但是当尝试使用其他方法时(将所有列分组并查找计数 > 1 的位置):
select count(*) from (
SELECT
a, b, c, d, e,
COUNT(*)
FROM
mytable
GROUP BY
a, b, c, d, e
HAVING
COUNT(*) > 1
)
我收到5,436。
为什么重复的数量不同? (20,943 与 5,436)
谢谢。
【问题讨论】:
标签: sql duplicates snowflake-cloud-data-platform