Trying to find max value of multiple sums

I’m trying to find the maximum value of several different sums, and can’t figure out the best way to write the code.

Basically, I have 8 different locations, with multiple data points. I’m trying to find which of the 8 locations has the highest total amount (sum of all the data points).

Currently I have the following

SELECT SUM(Value) FROM Observation WHERE VariableID=1 AND SiteID=10092700 

And I just repeat that each time (with different SiteIDs), which gives me a sum, which I can then see the max. But I need some code to give me the SiteID with the max value based on all the sums.

Hope this makes sense. Thanks

submitted by /u/SirBreauxseph
[link] [comments]


Go to Source of this post
Author Of this post: /u/SirBreauxseph
Title Of post: Trying to find max value of multiple sums
Author Link: {authorlink}