1
SELECT  
    tableResults.PoliticalParty, 
    MAX(PoliticalPartyVotes.TotalVotes) AS [EX11]
FROM
    (SELECT 
         tableResults.PoliticalParty, 
         SUM(INT(tableResults.Votes)) AS TotalVotes
     FROM tableResults 
     GROUP BY tableResults.PoliticalParty) AS PoliticalPartyVotes;

This doesn't work, tableResults.PoliticalParty not showing one one result with max.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

If you want the PoliticalParty with most votes, you can use ORDER BY and TOP (1) in your existing aggregate query:

SELECT TOP (1) PoliticalParty, Sum(INT(Votes)) AS TotalVotes
FROM tableResults 
GROUP BY tableResults.PoliticalParty
ORDER BY Sum(INT(Votes)) DESC

To allow top ties (ie, two PoliticalParty having the same, maximum total of votes), the you can use TOP (1) WITH TIES instead.

GMB
  • 216,147
  • 25
  • 84
  • 135