Challenge - 5 Problems
Aggregation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this COUNT query?
Consider a table employees with columns
id, department, and salary. The table has 5 rows with these departments: 'HR', 'IT', 'IT', 'HR', 'Finance'. What is the result of this query?SELECT COUNT(*) FROM employees WHERE department = 'IT';
PostgreSQL
SELECT COUNT(*) FROM employees WHERE department = 'IT';
Attempts:
2 left
💡 Hint
COUNT(*) counts all rows that match the condition.
✗ Incorrect
There are exactly 2 employees in the 'IT' department, so COUNT(*) returns 2.
❓ query_result
intermediate2:00remaining
What is the average salary for the HR department?
Given the employees table with
salary values: 50000, 60000, 55000, 70000, 65000 for departments 'HR', 'IT', 'IT', 'HR', 'Finance' respectively, what does this query return?SELECT AVG(salary) FROM employees WHERE department = 'HR';
PostgreSQL
SELECT AVG(salary) FROM employees WHERE department = 'HR';
Attempts:
2 left
💡 Hint
AVG calculates the average of the selected salaries.
✗ Incorrect
The HR salaries are 50000 and 70000. Their average is (50000 + 70000) / 2 = 60000.
📝 Syntax
advanced2:00remaining
Which query correctly sums salaries for Finance department?
Choose the query that correctly sums the salaries of employees in the 'Finance' department.
Attempts:
2 left
💡 Hint
SUM needs parentheses and WHERE clause after FROM.
✗ Incorrect
Option A uses correct syntax: SUM(salary) with WHERE clause after FROM. Others have syntax errors.
❓ query_result
advanced2:00remaining
What is the minimum salary in the employees table?
Given the salaries 50000, 60000, 55000, 70000, 65000 in the employees table, what does this query return?
SELECT MIN(salary) FROM employees;
PostgreSQL
SELECT MIN(salary) FROM employees;
Attempts:
2 left
💡 Hint
MIN returns the smallest value in the column.
✗ Incorrect
The smallest salary is 50000, so MIN(salary) returns 50000.
🧠 Conceptual
expert2:00remaining
Which aggregate function ignores NULL values in its calculation?
In SQL aggregation, which function does NOT count NULL values when computing its result?
Attempts:
2 left
💡 Hint
Think about how COUNT(*) differs from COUNT(column_name).
✗ Incorrect
COUNT(column_name) counts only non-NULL values, ignoring NULLs. COUNT(*) counts all rows including NULLs. SUM and AVG also ignore NULLs in their calculations.