0
0
PostgreSQLquery~20 mins

COUNT, SUM, AVG, MIN, MAX in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Aggregation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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';
A2
B3
C5
D0
Attempts:
2 left
💡 Hint
COUNT(*) counts all rows that match the condition.
query_result
intermediate
2: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';
A65000
B60000
C55000
D70000
Attempts:
2 left
💡 Hint
AVG calculates the average of the selected salaries.
📝 Syntax
advanced
2:00remaining
Which query correctly sums salaries for Finance department?
Choose the query that correctly sums the salaries of employees in the 'Finance' department.
ASELECT SUM(salary) FROM employees WHERE department = 'Finance';
BSELECT SUM salary FROM employees WHERE department = 'Finance';
CSELECT SUM(salary) FROM employees GROUP BY department = 'Finance';
DSELECT SUM(salary) WHERE department = 'Finance' FROM employees;
Attempts:
2 left
💡 Hint
SUM needs parentheses and WHERE clause after FROM.
query_result
advanced
2: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;
A60000
B55000
C50000
D65000
Attempts:
2 left
💡 Hint
MIN returns the smallest value in the column.
🧠 Conceptual
expert
2:00remaining
Which aggregate function ignores NULL values in its calculation?
In SQL aggregation, which function does NOT count NULL values when computing its result?
ACOUNT(*)
BAVG(column_name)
CSUM(column_name)
DCOUNT(column_name)
Attempts:
2 left
💡 Hint
Think about how COUNT(*) differs from COUNT(column_name).