gpt4 book ai didi

MySql Sql MAX 和 SUM 错误

转载 作者:行者123 更新时间:2023-11-29 05:00:06 24 4
gpt4 key购买 nike

select sum(value) as 'Value',max(value)
from table_name where sum(value)=max(sum(value)) group by id_name;

错误是:组函数的使用无效(ErrorNr.1111)

有什么想法吗?

谢谢。

最佳答案

你可以试试吗

SELECT Value, MXValue
FROM (
select sum(value) as 'Value',max(value) MXValue
from table_name
group by id_name
) as t1
order by value desc
LIMIT 0,1

来自 MySQL Forums :: General :: selecting MAX(SUM())

或者你可以尝试类似的东西

SELECT  id_name,
Value
FROM (
select id_name,sum(value) as 'Value'
from table_name
group by id_name
) t
WHERE Value = (
SELECT TOP 1 SUM(Value) Mx
FROM table_name
GROUP BY id_name
ORDER BY SUM(Value) DESC
)

甚至使用内部连接

SELECT  id_name,
Value
FROM (
select id_name,sum(value) as Value
from table_name
group by id_name
) t INNER JOIN
(
SELECT TOP 1 SUM(Value) Mx
FROM table_name
GROUP BY id_name
ORDER BY SUM(Value) DESC
) m ON Value = Mx

关于MySql Sql MAX 和 SUM 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2076831/

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