The difference between countDistinct and distinct.count

前端 未结 3 359
借酒劲吻你
借酒劲吻你 2021-01-15 20:09

Why do I get different outputs for ..agg(countDistinct(\"member_id\") as \"count\") and ..distinct.count? Is the difference the same as between

3条回答
  •  深忆病人
    2021-01-15 21:00

    Why do I get different outputs for ..agg(countDistinct("member_id") as "count") and ..distinct.count?

    Because .distinct.count is the same:

    SELECT COUNT(*) FROM (SELECT DISTINCT member_id FROM table)
    

    while ..agg(countDistinct("member_id") as "count") is

    SELECT COUNT(DISTINCT member_id) FROM table
    

    and COUNT(*) uses different rules than COUNT(column) when nulls are encountered.

提交回复
热议问题