gpt4 book ai didi

mysql - 如何在 mySQL 中正确包装 sum(quantity) = max(sum(quantities)) ?

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

我想要取每个唯一属性的总和,然后取这些值的最大值。关于如何使用 mySQL 执行此操作有什么建议吗?我不断收到“无效使用群组功能”的消息。

+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| matchName | varchar(26) | YES | MUL | NULL | |
| winner | varchar(26) | YES | | NULL | |
| loser | varchar(26) | YES | | NULL | |
| winningGame | varchar(26) | YES | | NULL | |
| dateofWin | date | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+

+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| matchName | varchar(26) | NO | PRI | | |
| date | date | YES | | NULL | |
| grandPrize | int(11) | YES | | NULL | |
| location | varchar(26) | YES | | NULL | |
| state | varchar(26) | YES | | NULL | |
| attendance | int(11) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+

到目前为止,我最接近的是使用:

select Results.winner, Tourney.grandPrize 
from Tourney
inner join Results
on Results.matchName=Tourney.matchName;

最佳答案

你的问题很不清楚,

我已经投票给@A.D.评论,您应该提供更多详细信息,表结构,数据样本,预期结果,当前带来错误的查询等。

但是您的问题的快速答案是:

SELECT t.*, MAX(t.sum_qty) as max_qty
FROM (
SELECT *, SUM(qty) as sum_qty
FROM test
GROUP BY order_id // you can set any group field you need here
) AS t

关于mysql - 如何在 mySQL 中正确包装 sum(quantity) = max(sum(quantities)) ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28746570/

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