$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #230

Which fix removes the bug?

SELECT dept, COUNT(*)
FROM emp
WHERE COUNT(*) > 5
GROUP BY dept;
  1. Use COUNT(dept) in WHERE
  2. Move the test into HAVING
  3. Put WHERE after the GROUP BY
  4. Alias it: COUNT(*) AS n
WHERE filters rows before grouping, so aggregates are not allowed there; HAVING filters the groups.
Play Problem Solving ▸