SQL COUNT Column

Counting a specific column only counts its non-NULL values — this is where it diverges from COUNT(*).

What & Why

COUNT(column_name) counts only the rows where that column has an actual, non-NULL value. Rows where it's NULL are skipped entirely.

See How It Works

BUSINESS QUESTION

Count only product feedback rows that contain an NPS score.

iduser_idfeature_idratingnps_scorecommentcreated_at
1101159Clear and useful2024-01-25 12:15:00+00
210224NULLExport worked well2024-02-20 15:40:00+00
3103147Helpful setup flow2024-03-18 09:05:00+00
410433NULLNeeds clearer timing2024-04-08 17:30:00+00
EXAMPLE QUERY
SELECT COUNT(nps_score) AS scored_feedback
FROM product.feedback;
RESULT — NULL scores are skipped
scored_feedback
2

Two of the four product.feedback rows contain an nps_score.

Now You Try

Practice this concept

Marketing wants total leads, qualified leads, and converted leads in one summary row.

Available schema
marketing

Prefix tables with marketing.table_name.

total_leadsqualified_leadsconverted_leads
marketing.leads
ColumnType
idinteger
campaign_idinteger
emailtext
created_attimestamp with time zone
qualified_attimestamp with time zone
converted_attimestamp with time zone
lead_scoreinteger
sourcetext
countrytext
archive_statustext
query.sql
Beginner business practice

Sign up free to try it on a real business scenario