Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to group the sales by product.
SQL
SELECT product, SUM(amount) FROM sales [1] product; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY
Using WHERE to group rows
✗ Incorrect
To group rows by a column, use GROUP BY.
2fill in blank
mediumComplete the code to order the grouped results by total sales descending.
SQL
SELECT product, SUM(amount) AS total FROM sales GROUP BY product [1] total DESC; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GROUP BY again instead of ORDER BY
Using WHERE to sort results
✗ Incorrect
To sort results, use ORDER BY followed by the column and direction.
3fill in blank
hardFix the error in the query to correctly group and order by the count of orders.
SQL
SELECT customer_id, COUNT(*) AS order_count FROM orders [1] customer_id ORDER BY order_count DESC; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY in the grouping clause
Omitting GROUP BY entirely
✗ Incorrect
The query must use GROUP BY to group by customer_id before ordering.
4fill in blank
hardFill both blanks to group sales by region and order by average amount ascending.
SQL
SELECT region, AVG(amount) AS avg_amount FROM sales [1] region [2] avg_amount ASC;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping GROUP BY and ORDER BY clauses
Using WHERE instead of GROUP BY
✗ Incorrect
Use GROUP BY to group by region and ORDER BY to sort by average amount.
5fill in blank
hardFill all three blanks to select product, count orders, and order by count descending.
SQL
SELECT [1], COUNT(*) AS [2] FROM orders [3] [1] ORDER BY [2] DESC;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY for grouping
Not matching the alias name in ORDER BY
✗ Incorrect
Select the product column, name the count as order_count, and group by product to count orders per product.