gpt4 book ai didi

MySQL - 按月的最大摘要

转载 作者:行者123 更新时间:2023-11-29 07:31:32 26 4
gpt4 key购买 nike

我有这个实体:

payments(idPayment, idGroup, price, paymentDate)

我想找出最大月份(可记录的月份)。我有最高价,但月份不对。

Select Max(x.price), x.month, x.year from(
SELECT SUM(price) as price, Year(paymensDate) as year, Month(paymentDate) as month FROM `payments`
where idGroup=27 group by Year(paymentDate), Month(paymentDate)
) as x

多谢指教

最佳答案

您可以使用ORDER BYLIMIT 来选择价格最高的行

SELECT SUM(price) as price, 
YEAR(paymensDate) as year,
MONTH(paymentDate) as month
FROM `payments`
WHERE idGroup=27
GROUP BY YEAR(paymentDate),
MONTH(paymentDate)
ORDER BY price DESC
LIMIT 1

MAX 将为提供的列提供最大值,但不保证列的其他值返回与 max 选取的行相同的值

关于MySQL - 按月的最大摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51028902/

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