Reputation: 1015
This is the first part of a crazy query I have to put together so expect another question on here soon!
I have this table
What I am trying to do is to get a list of CONTEXT
that have a SUM(FILE_SIZE)
greater than 5 gigs.
I have every part of the query figured out except putting in the where clause.
SELECT CONTEXT,SUM(FILE_SIZE) AS size FROM CONTENT_RESOURCE GROUP BY CONTEXT.
What I'm having trouble putting together is something like:
WHERE SUM(FILE_SIZE) > 5000000000
This would be done for each unique CONTEXT.
So if there is data like this:
1 | A
4 | A
2 | C
6 | C
8 | B
The result would be something like:
5 | A
8 | C
8 | B
So I need to get the SUM(FILE_SIZE)
for all of the different CONTEXT
s and then only return the ones where it is greater than 5000000000
Upvotes: 1
Views: 34
Reputation: 311823
The having
clause allows you to apply conditions on groups (and aggregate results) created by the group by
clause:
SELECT context, SUM(file_size) AS size
FROM content_resource
GROUP BY context
HAVING SUM(file_size) > 5000000000
Upvotes: 2