What does SELECT dept, COUNT(*) FROM employees GROUP BY dept produce?
Correct answer
B. One row per department with its employee count
14 views
B. One row per department with its employee count
14 views
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.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.