Bird
0
0

Why does COUNT(column) OVER() count differently than COUNT(*) OVER() in PostgreSQL?

hard📝 Conceptual Q10 of 15
PostgreSQL - Window Functions in PostgreSQL
Why does COUNT(column) OVER() count differently than COUNT(*) OVER() in PostgreSQL?
ACOUNT(column) counts all rows; COUNT(*) counts only distinct rows
BBoth count the same number of rows regardless of nulls
CCOUNT(column) counts only non-null values; COUNT(*) counts all rows
DCOUNT(*) counts only non-null values; COUNT(column) counts all rows
Step-by-Step Solution
Solution:
  1. Step 1: Understand COUNT(column) behavior

    COUNT(column) counts only rows where the column is not null.
  2. Step 2: Understand COUNT(*) behavior

    COUNT(*) counts all rows regardless of nulls in any column.
  3. Final Answer:

    COUNT(column) counts only non-null values; COUNT(*) counts all rows -> Option C
  4. Quick Check:

    COUNT(column) excludes nulls; COUNT(*) includes all rows [OK]
Quick Trick: COUNT(column) skips nulls; COUNT(*) counts all rows [OK]
Common Mistakes:
  • Assuming COUNT(column) counts all rows
  • Confusing COUNT(*) with COUNT(DISTINCT)
  • Ignoring null value effect on COUNT(column)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes