0
0
SQLquery~10 mins

How GROUP BY changes query execution in SQL - Interactive Practice

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

Complete the code to group rows by the column 'category'.

SQL
SELECT category, COUNT(*) FROM products [1] category;
Drag options to blanks, or click blank then click option'
AWHERE
BORDER BY
CGROUP BY
DHAVING
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY
Using WHERE to filter groups
2fill in blank
medium

Complete the code to filter groups having more than 5 items.

SQL
SELECT category, COUNT(*) FROM products GROUP BY category [1] COUNT(*) > 5;
Drag options to blanks, or click blank then click option'
AHAVING
BWHERE
CORDER BY
DGROUP BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of HAVING to filter groups
Using ORDER BY to filter groups
3fill in blank
hard

Fix the error in the query by completing the blank with the correct clause.

SQL
SELECT category, price FROM products [1] category;
Drag options to blanks, or click blank then click option'
AORDER BY
BWHERE
CGROUP BY
DHAVING
Attempts:
3 left
💡 Hint
Common Mistakes
Using GROUP BY without aggregation causing errors
Using HAVING without GROUP BY
4fill in blank
hard

Fill both blanks to group by 'department' and filter groups with average salary above 50000.

SQL
SELECT department, AVG(salary) FROM employees [1] department [2] AVG(salary) > 50000;
Drag options to blanks, or click blank then click option'
AGROUP BY
BWHERE
CHAVING
DORDER BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of HAVING to filter groups
Not grouping before filtering groups
5fill in blank
hard

Fill all three blanks to select department names in uppercase, average salary as avg_sal, and filter groups with avg_sal above 60000.

SQL
SELECT [1], AVG(salary) AS [2] FROM employees [3] department HAVING AVG(salary) > 60000;
Drag options to blanks, or click blank then click option'
AUPPER(department)
Bavg_sal
CGROUP BY
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Not aliasing the aggregate column
Using HAVING without GROUP BY
Selecting columns not in GROUP BY or aggregated