0
0
MySQLquery~10 mins

GROUP BY clause in MySQL - 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 results by the "department" column.

MySQL
SELECT department, COUNT(*) FROM employees [1] department;
Drag options to blanks, or click blank then click option'
AWHERE
BORDER BY
CHAVING
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 show the average salary for each job title.

MySQL
SELECT job_title, AVG(salary) FROM employees [1] job_title;
Drag options to blanks, or click blank then click option'
AGROUP BY
BWHERE
CLIMIT
DORDER BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY.
Forgetting to group when using AVG.
3fill in blank
hard

Fix the error in the query to correctly group by "category".

MySQL
SELECT category, SUM(quantity) FROM sales [1];
Drag options to blanks, or click blank then click option'
AGROUP BY category
BGROUP category
CGROUPBY category
DGROUP BY
Attempts:
3 left
💡 Hint
Common Mistakes
Writing GROUP category without BY.
Writing GROUPBY as one word.
4fill in blank
hard

Fill both blanks to group by "region" and filter groups with total sales over 1000.

MySQL
SELECT region, SUM(sales) FROM sales_data [1] region [2] SUM(sales) > 1000;
Drag options to blanks, or click blank then click option'
AGROUP BY
BORDER BY
CHAVING
DWHERE
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of HAVING to filter groups.
Forgetting to group before filtering.
5fill in blank
hard

Fill all three blanks to select the department name, count employees, and filter departments with more than 5 employees.

MySQL
SELECT [1], COUNT(*) FROM employees [2] [1] [3] COUNT(*) > 5;
Drag options to blanks, or click blank then click option'
Adepartment
BGROUP BY
CHAVING
DORDER BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of HAVING to filter groups.
Not grouping by the selected column.