0
0
SQLquery~10 mins

GROUP BY with ORDER BY in SQL - Interactive Code Practice

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

Complete 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'
AHAVING
BORDER BY
CWHERE
DGROUP BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY
Using WHERE to group rows
2fill in blank
medium

Complete 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'
AORDER BY
BGROUP BY
CWHERE
DHAVING
Attempts:
3 left
💡 Hint
Common Mistakes
Using GROUP BY again instead of ORDER BY
Using WHERE to sort results
3fill in blank
hard

Fix 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'
AORDER BY
BGROUP BY
CWHERE
DHAVING
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY in the grouping clause
Omitting GROUP BY entirely
4fill in blank
hard

Fill 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'
AGROUP BY
BORDER BY
CWHERE
DHAVING
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping GROUP BY and ORDER BY clauses
Using WHERE instead of GROUP BY
5fill in blank
hard

Fill 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'
Aproduct
Border_count
CGROUP BY
DORDER BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY for grouping
Not matching the alias name in ORDER BY