gpt4 book ai didi

c# - 如何计算选票的正确语法是什么

转载 作者:行者123 更新时间:2023-11-29 10:37:26 25 4
gpt4 key购买 nike

这是我们用来计算投票学生人数的代码。

SELECT candidate,position, COUNT(studentNumber) AS 'Candidate Votes'
FROM dbvotingsystem.votes WHERE organization = 'iSITE' GROUP BY candidate
ORDER BY position;

该图像是表格中数据的示例。

enter image description here om/CwvSt.png

最佳答案

如果获胜者是每组中最大候选人投票,那么秘书的获胜者应该是许多、检查以下sql:

SELECT
position,
substring_index(group_concat(candidate order by `Candidate Votes` desc), ',', 1) winner,
max(`Candidate Votes`) as `Candidate Votes`
FROM (
SELECT candidate, position, COUNT(studentNumber) AS 'Candidate Votes'
FROM dbvotingsystem.votes
WHERE organization = 'iSITE'
GROUP BY candidate
) votes
GROUP BY position

结果:

|    position | winner | Candidate Votes |
|-------------|--------|-----------------|
| President | Audrey | 7 |
| Secretary | Many | 8 |
| Treasurer | Barry | 10 |
| V.President | Juan | 9 |

DEMO在 SQLFiddle 中。

关于c# - 如何计算选票的正确语法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46172421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com