Skip to content

Instantly share code, notes, and snippets.

@tanelsuurhans
Created February 12, 2013 00:36
Show Gist options
  • Save tanelsuurhans/4759002 to your computer and use it in GitHub Desktop.
Save tanelsuurhans/4759002 to your computer and use it in GitHub Desktop.
SELECT id,
sum(hours) AS totalhours
FROM mytable
GROUP BY id
HAVING sum(hours) > 50;
If you really can't be bothered to write sum() twice, you could consider
a two-level SELECT:
SELECT * FROM
(SELECT id,
sum(hours) AS totalhours
FROM mytable
GROUP BY id) ss
WHERE totalhours > 50;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment