total amount of rows表中具有相同键的行的百分比

z9zf31ra  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(341)

我需要找到表中重复日志的百分比。因此,我使用“having”进行查询,检查密钥是否重复。问题是,在做了这个“拥有”之后,我丢失了所有没有复制的日志。
这是table:

我的问题是:

(SELECT count(params_advertiserId) AS duplicates 
 FROM android_clicks 
 GROUP BY params_advertiserId ,app_id ,date --my key is a triplet
 HAVING COUNT(params_advertiserId) > 1)

我们将不胜感激。

n3h0vuf2

n3h0vuf21#

这就是你想要的?

select (count(*) - count(distinct params_advertiserId, app_id, date)) / count(*) as duplicate_ratio
from android_clicks ac;

您的查询不正确,因为 AND 用于布尔表达式。所以 GROUP BY 表达式为真、假或 NULL .
如果需要计数,请将其 Package 为子查询:

SELECT COUNT(*) as num_duplicates
FROM (SELECT params_advertiserId, app_id, date AS duplicates 
      FROM android_clicks ac
      GROUP BY params_advertiserId, app_id, date 
      HAVING COUNT(*) > 1
     );
o7jaxewo

o7jaxewo2#

GROUP BY 使用逗号 , 而不是 AND ```
SELECT count(params_advertiserId) AS duplicates
FROM android_clicks
GROUP BY params_advertiserId , app_id , date
HAVING COUNT(params_advertiserId) > 1

相关问题