1

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 Table Description

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 CONTEXTs and then only return the ones where it is greater than 5000000000

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I didn't run the query yet as it takes 10-20 minutes to complete but I tested it on a smaller data set and it looked like it worked. Expect a few more SQL questions today too!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.