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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.