gpt4 book ai didi

mysql从多个和中选择最大值

转载 作者:行者123 更新时间:2023-11-29 12:05:07 27 4
gpt4 key购买 nike

我正在使用以下结果表

Results Table
__________________________________________
player_a| player_b | player_c | year
________|________ |__________|___________|
100 150 150 2015
100 -50 -50 2015
100 350 250 2014
200 350 250 2014

我想做的是获取每个玩家每年的总和。使用以下选择我得到了想要的结果。

SELECT (

SELECT SUM( player_a )
FROM `results`
WHERE year =2015
) AS player_a_2015, (

SELECT SUM( player_a)
FROM `results`
WHERE year =2014
) AS player_a_2014

如何才能只得到最大总和结果?

ie 对于player_a 应该是 300

最佳答案

SELECT SUM(player_a) AS spa
FROM results
GROUP BY year
ORDER BY spa DESC
LIMIT 1

关于mysql从多个和中选择最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634712/

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