1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What does SELECT dept, COUNT(*) FROM employees GROUP BY…

Added 30 Nov -0001

What does SELECT dept, COUNT(*) FROM employees GROUP BY dept produce?

  1. One row per department with the sum of salaries
  2. One row per department with its employee count Correct answer
  3. One row per employee with the department name
  4. A single row with the total employee count

Correct answer

B. One row per department with its employee count

14 views

MCQSEXAM

Explanation

GROUP BY collapses rows sharing the same dept value and COUNT(*) then counts the rows inside each group, so the output has one row per distinct department. Any column in the SELECT list must either be grouped or wrapped in an aggregate, which stricter engines such as PostgreSQL enforce. Omitting the GROUP BY clause would instead give a single overall count.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs