Skip to content

Instantly share code, notes, and snippets.

@gphil
Created September 4, 2012 19:57
Show Gist options
  • Save gphil/3625707 to your computer and use it in GitHub Desktop.
Save gphil/3625707 to your computer and use it in GitHub Desktop.
Using GROUP BY instead of HAVING
SELECT icps.city, icps.state, icps.ice_cream_parlor
FROM ice_cream_parlors icps
INNER JOIN (
SELECT city, state, count(ice_cream_parlor) icp_count
FROM ice_cream_parlors icps
GROUP by city, state
) sq
ON icps.city = sq.city and icps.state = sq.state
GROUP BY icps.city, icps.state, icps.ice_cream_parlor
WHERE sq.icp_count > 5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment