0
0
PostgreSQLquery~10 mins

Why aggregation matters in PostgreSQL - Test Your Understanding

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

Complete the code to count the number of orders in the orders table.

PostgreSQL
SELECT [1](order_id) FROM orders;
Drag options to blanks, or click blank then click option'
AMIN
BSUM
CMAX
DCOUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of COUNT will try to add order IDs, which may not make sense.
Using MAX or MIN returns the highest or lowest order ID, not the count.
2fill in blank
medium

Complete the code to find the average price from the products table.

PostgreSQL
SELECT [1](price) FROM products;
Drag options to blanks, or click blank then click option'
AAVG
BMIN
CSUM
DCOUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM returns the total price, not the average.
Using COUNT returns the number of prices, not their average.
3fill in blank
hard

Fix the error in the query to get the total quantity sold from sales.

PostgreSQL
SELECT [1](quantity) FROM sales;
Drag options to blanks, or click blank then click option'
ACOUNT
BSUM
CAVG
DMAX
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT counts rows, not the total quantity.
Using AVG returns the average quantity, not the total.
4fill in blank
hard

Fill both blanks to get the number of orders per customer.

PostgreSQL
SELECT customer_id, [1](order_id) FROM orders GROUP BY [2];
Drag options to blanks, or click blank then click option'
ACOUNT
BSUM
Ccustomer_id
Dorder_id
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by order_id would group each order separately.
Using SUM instead of COUNT counts values, not rows.
5fill in blank
hard

Fill all three blanks to find the average price per category for products priced above 100.

PostgreSQL
SELECT [1], [2](price) FROM products WHERE price [3] 100 GROUP BY category;
Drag options to blanks, or click blank then click option'
Acategory
BAVG
C>
DSUM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of AVG calculates total price, not average.
Using < instead of > filters prices below 100.