0
0
PostgreSQLquery~10 mins

COUNT, SUM, AVG, MIN, MAX in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to count all rows in the employees table.

PostgreSQL
SELECT [1](*) FROM employees;
Drag options to blanks, or click blank then click option'
AAVG
BSUM
CCOUNT
DMIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of COUNT will cause an error or wrong result.
Using AVG or MIN does not count rows.
2fill in blank
medium

Complete the code to find the total salary from the employees table.

PostgreSQL
SELECT [1](salary) FROM employees;
Drag options to blanks, or click blank then click option'
ASUM
BAVG
CMAX
DCOUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT will count rows, not add salaries.
Using AVG will give average salary, not total.
3fill in blank
hard

Fix the error in the code to get the average age from the users table.

PostgreSQL
SELECT [1](age) FROM users;
Drag options to blanks, or click blank then click option'
ACOUNT
BAVG
CSUM
DMIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM or COUNT will not give the average.
Using MIN gives the smallest value, not average.
4fill in blank
hard

Fill both blanks to find the minimum and maximum price from the products table.

PostgreSQL
SELECT [1](price) AS min_price, [2](price) AS max_price FROM products;
Drag options to blanks, or click blank then click option'
AMIN
BMAX
CSUM
DCOUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping MIN and MAX will give wrong results.
Using SUM or COUNT here is incorrect.
5fill in blank
hard

Fill all three blanks to get the count of orders, total amount, and average amount from the orders table.

PostgreSQL
SELECT [1](*) AS total_orders, [2](amount) AS total_amount, [3](amount) AS average_amount FROM orders;
Drag options to blanks, or click blank then click option'
ACOUNT
BSUM
CAVG
DMIN
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up SUM and AVG functions.
Using MIN instead of AVG for average.