QuizzesCOUNT(DISTINCT col) & Approximate Counting — Concept Check
intermediate
sql

COUNT(DISTINCT col) & Approximate Counting — Concept Check

Questions on COUNT(DISTINCT col) & Approximate Counting. COUNT(DISTINCT col) counts unique non-NULL values but is expensive on large tables; approximate algorithms like HyperLogLog offer near-linear performance with small, configurable error.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on COUNT(DISTINCT col) & Approximate Counting — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A large table in your database needs frequent distinct counts for analytics. Which approach offers better performance with acceptable accuracy for this use case?

    • AUse COUNT(*) to include all rows
    • BUse HyperLogLog for approximate counting
    • CUse COUNT(col) to exclude NULLs
    • DUse COUNT(DISTINCT col) for exact results
  2. 2.You need to count distinct user_id and product_id combinations in a table. Which SQL method is appropriate?

    • AUse COUNT(*) directly
    • BUse a subquery with SELECT DISTINCT
    • CUse COUNT(DISTINCT user_id, product_id)
    • DUse COUNT(DISTINCT CONCAT(user_id, product_id))
  3. 3.An analyst uses COUNT(DISTINCT col) on a table with millions of rows. They report slow performance. What is likely happening?

    • AThe operation is building an in-memory hash of distinct values
    • BThe operation is parallelized across multiple cores
    • CThe operation is using constant memory
    • DThe operation is skipping NULL values
  4. 4.A PostgreSQL user wants to count distinct user_ids with minimal resource use. What should they do?

    • AUse COUNT(*)
    • BInstall pg_hll and use HyperLogLog
    • CUse COUNT(DISTINCT user_id)
    • DUse COUNT(user_id)
  5. 5.When using COUNT(DISTINCT col), why might the result be lower than expected?

    • ANULL values are excluded from the count
    • BThe count is parallelized, causing errors
    • CThe count includes all rows
    • DThe count includes duplicate values
  6. 6.Which SQL function should you use for accurate billing purposes?

    • AAPPROX_COUNT_DISTINCT
    • BCOUNT(DISTINCT col)
    • CCOUNT(*)
    • DHyperLogLog
  7. 7.A developer uses COUNT(DISTINCT CONCAT(user_id, '-', product_id)) to count combinations. What risk does this approach have?

    • ALess accurate than COUNT(*)
    • BCollision risk with short values
    • CRequires more memory
    • DExcludes NULL values
  8. 8.What is a major advantage of using HyperLogLog over COUNT(DISTINCT col) for analytics?

    • AIncludes NULL values
    • BUses constant memory regardless of cardinality
    • CProvides exact counts
    • DRequires no extensions