COUNT, SUM, AVG, MIN, MAX Deep Dive — Concept Check
Questions on COUNT, SUM, AVG, MIN, MAX Deep Dive. SQL aggregate functions collapse multiple rows into a single value, but NULL handling, floating-point precision in AVG, and conditional aggregation are frequent sources of subtle bugs.
Questions in this quiz
8 questions on COUNT, SUM, AVG, MIN, MAX Deep Dive — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A report shows that the SUM of a column is NULL. What can be inferred?
- AThere are no rows in the table.
- BThe column contains only zeros.
- CAll values in the column are NULL.
- DThe column contains non-numeric data.
2.In a table with 10 rows, 3 of which have a NULL amount, what does AVG(amount) calculate?
- ASUM of 10 values divided by 10
- BSUM of 10 values divided by 7
- CSUM of 7 values divided by 10
- DSUM of 7 values divided by 7
3.You want to count all orders, including those with NULL amounts. Which function do you use?
- ASUM(amount)
- BCOUNT(*)
- CCOUNT(DISTINCT amount)
- DCOUNT(amount)
4.How does COUNT(DISTINCT col) differ from COUNT(col)?
- ACounts NULLs as zero
- BCounts only the first occurrence of each value
- CRemoves duplicates before counting
- DIgnores all NULLs
5.A query uses SUM(amount) FILTER (WHERE status = 'completed'). What does it do?
- ASums all amounts, ignoring status
- BSums amounts excluding 'completed' status
- CSums amounts for 'completed' and 'pending' statuses
- DSums amounts only for 'completed' status
6.What happens if you use AVG without casting to NUMERIC on a salary column?
- AAVG will return NULL
- BAVG will count NULLs as zero
- CPotential floating-point imprecision
- DAVG will be faster
7.Which function will count only non-NULL user IDs in a table?
- ACOUNT(*)
- BCOUNT(user_id)
- CSUM(user_id)
- DAVG(user_id)
8.Why might SUM(CASE WHEN status = 'completed' THEN amount END) be used?
- ATo filter out NULL amounts
- BTo sum all amounts regardless of status
- CTo pivot row data into columns
- DTo count all completed statuses