Summarising data quiz

  • Admin
  • 1 min read

Nine questions on DISTINCT, aggregates, GROUP BY and HAVING.

SQL

Summarising data quiz

9 questions, instant feedback

Question 1 of 9
Question 1 of 9 Which keyword removes duplicate rows from a result?
Why this is the answer

SELECT DISTINCT compares the whole selected row and keeps one copy of each distinct combination.

Question 2 of 9
Question 2 of 9 What does COUNT(*) count?
Why this is the answer

COUNT(*) counts rows. COUNT(column) counts only rows where that column is not null, which is why the two can differ.

Question 3 of 9
Question 3 of 9 What does AVG ignore?
Why this is the answer

Aggregate functions skip NULLs. AVG divides the sum by the number of non-null values, not by the row count.

Question 4 of 9
Question 4 of 9 Which clause groups rows that share a value?
Why this is the answer

GROUP BY collapses rows with equal values in the listed columns into one row per group.

Question 5 of 9
Question 5 of 9 Which clause filters groups after aggregation?
Why this is the answer

HAVING applies to aggregated results, so it can test COUNT(*) or SUM(amount). WHERE cannot.

Question 6 of 9
Question 6 of 9 A query selects category and COUNT(*) with no GROUP BY. What happens in most engines?
Why this is the answer

Without GROUP BY, mixing a plain column with an aggregate is invalid in standard SQL. SQLite allows it and picks an arbitrary value, which hides the mistake.

Question 7 of 9
Question 7 of 9 What does SUM return when every value is NULL?
Why this is the answer

SUM of no values is NULL, not zero. Wrap it in COALESCE(SUM(x), 0) when a report needs a number.

Question 8 of 9
Question 8 of 9 Which expression rounds an average to two decimals?
Why this is the answer

Round the finished average. Rounding each price first changes the value being averaged.

Question 9 of 9
Question 9 of 9 Where does HAVING belong in a query?
Why this is the answer

The written order is SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT. HAVING follows the grouping it filters.

Your answers stay in this browser. Nothing is sent to a server.