简体   繁体   English

MS Access 中的 SQL 总和最大值

[英]SQL in MS Access max of sum

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.这不起作用, tableResults.PoliticalParty没有显示一个最大的结果。

If you want the PoliticalParty with most votes, you can use ORDER BY and TOP (1) in your existing aggregate query:如果您想要获得最多票数的PoliticalParty ,您可以在现有的聚合查询中使用ORDER BYTOP (1)

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.要允许最高票数(即两个PoliticalParty拥有相同的最大总票数),您可以使用TOP (1) WITH TIES代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM