Bird
0
0

Which of the following SQL queries correctly uses GROUP BY to count employees per department?

easy📝 Syntax Q12 of 15
SQL - GROUP BY and HAVING
Which of the following SQL queries correctly uses GROUP BY to count employees per department?
ASELECT department, COUNT(*) FROM employees GROUP BY.;
BSELECT department, COUNT(*) FROM employees GROUP BY department.;
CSELECT department, COUNT(*) FROM employees WHERE department GROUP BY.;
DSELECT department, COUNT(*) FROM employees.;
Step-by-Step Solution
Solution:
  1. Step 1: Check the syntax of GROUP BY usage

    The correct syntax requires specifying the column after GROUP BY and using aggregate functions properly.
  2. Step 2: Analyze each option

    Only SELECT department, COUNT(*) FROM employees GROUP BY department; correctly groups by department and counts employees. The other options have syntax errors: missing column after GROUP BY, no GROUP BY clause, or invalid WHERE syntax.
  3. Final Answer:

    SELECT department, COUNT(*) FROM employees GROUP BY department; -> Option B
  4. Quick Check:

    GROUP BY column + aggregate function = correct syntax [OK]
Quick Trick: GROUP BY must be followed by column names, aggregate functions used outside [OK]
Common Mistakes:
MISTAKES
  • Omitting column after GROUP BY
  • Using WHERE incorrectly with GROUP BY
  • Missing aggregate function with GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes