HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How can i return the max of a sum by each team?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sumcantheeachreturnteammaxhow

Problem

I have a lot of teams and i want to know the maximum of sum total of each team.

This's my query :

SELECT campaign_id, 
       campaign_identifier, 
       team, 
       campaign_name, 
       Month(time) AS month, 
       Sum (total) AS Total 
FROM   campaign 
WHERE  Year(time) = Year(Now()) 
       AND Month(time) = 12 
GROUP  BY campaign_identi, 
          team


Thanks.

Solution

If am not wrong this is what you need

select team,max(Total)
from
(
SELECT team, 
       Sum (total) AS Total 
FROM   campaign 
WHERE  Year(time) = Year(Now()) 
       AND Month(time) = 12 
GROUP  BY campaign_identi, 
          team 
) A
Group by team

Code Snippets

select team,max(Total)
from
(
SELECT team, 
       Sum (total) AS Total 
FROM   campaign 
WHERE  Year(time) = Year(Now()) 
       AND Month(time) = 12 
GROUP  BY campaign_identi, 
          team 
) A
Group by team

Context

StackExchange Database Administrators Q#124193, answer score: 7

Revisions (0)

No revisions yet.