Learn with Abdou

INTERACTIVE LECTURES

Summarize and compare

Guided class activity · apply the ideas from the full SQL lessons.

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Count rows and known values

Step 1 of 4 · Database: Northshore Coffee

READ & UNDERSTAND

COUNT(*) counts rows. COUNT(calories) counts rows with a non-NULL calorie value. COUNT(DISTINCT category) counts different known categories. Always say what is being counted.

NULL means a value is missing or unknown; it is not automatically zero. AVG ignores NULL values, so an average may describe only part of the menu. State the denominator alongside your conclusion.

Worked example
SELECT COUNT(*) AS items, COUNT(calories) AS known_calories FROM menu_items;

Both aggregates consume the same menu_items rows, but COUNT(calories) ignores rows where that value is NULL. Subtracting known_calories from items reveals how many rows lack that field.

This returns one summary row because there is no GROUP BY. Neither number measures the number of categories; that requires counting distinct category values.

Your question

Return COUNT(*) AS item_count and COUNT(DISTINCT category) AS category_count from menu_items.

Explain your evidence

Why are item_count and category_count answering different questions?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · Northshore Coffee

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

Query results

Predict the result, then run your query.

Predict the result, then run your query.

Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.

Explore this query freely in the playground ↗

Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.