In SQL aggregation, does COUNT(column_name) tally only rows where the column is non-NULL, ignoring NULLs?

Difficulty: Easy

Correct Answer: Applies — COUNT(column) skips NULLs; only non-NULL rows are counted

Explanation:


Introduction / Context:
This question assesses understanding of how SQL aggregate functions handle NULL values, specifically the difference between COUNT(column) and COUNT().



Given Data / Assumptions:

  • COUNT(column) counts non-NULL occurrences in that column.
  • COUNT() counts rows regardless of NULLs in any column.
  • NULL represents “unknown/absent” and is ignored by most aggregates except COUNT().



Concept / Approach:
Aggregates (SUM, AVG, MAX, MIN, COUNT(column)) generally skip NULL inputs; COUNT() is special because it counts rows, not values. Understanding this distinction is crucial for accurate reports.



Step-by-Step Solution:
Identify which COUNT variant is used.Recall rule: COUNT(column) counts only non-NULL values in that column.Therefore rows where column_name IS NULL are not tallied.Hence the statement is correct.



Verification / Alternative check:
Quick test: a table with 3 rows where column values are (10, NULL, 30) yields COUNT(column)=2, COUNT()=3.



Why Other Options Are Wrong:
COUNT(column) does not include NULLs; DISTINCT is orthogonal (it deduplicates non-NULLs). COUNT(*) differs in semantics and always counts every row.



Common Pitfalls:
Expecting AVG on a column with NULLs to divide by total rows; it divides by the count of non-NULL values. Use COALESCE if you must treat NULLs as zeros.



Final Answer:
Applies — COUNT(column) skips NULLs; only non-NULL rows are counted

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion