MySql Sql MAX 和 SUM 错误
select sum(value) as 'Value',max(value)
from table_name where sum(value)=max(sum(value)) group by id_name;
错误是:组函数的使用无效(ErrorNr.1111)
有什么想法吗?
谢谢。
select sum(value) as 'Value',max(value)
from table_name where sum(value)=max(sum(value)) group by id_name;
The error is: Invalid use of group function (ErrorNr. 1111)
Any idea?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试
从 MySQL 论坛 :: 常规 :: 选择 MAX (SUM())
或者你可以尝试类似
Or 甚至使用 Inner join
Can you maybe try
From MySQL Forums :: General :: selecting MAX(SUM())
Or you could try something like
Or even with an Inner join
=max(sum(value))
部分需要比较两个分组选择的结果,而不仅仅是一个。 (总和的最大值。)不过,让我们退后一步:您实际上想要获取什么信息?因为表中的值的总和是唯一的;没有最小值或最大值(或者,根据您的观点,存在 - 该值是其自身的最小值和最大值)。您需要在其中应用一些进一步的标准,以使结果有意义,并且在此过程中,您可能需要使用某些标准进行联接或子选择。
The
=max(sum(value))
part requires comparing the results of two grouped selects, not just one. (The max of the sum.)Let's step back, though: What information are you actually trying to get? Because the sum of the values in the table is unique; there is no minimum or maximum (or, depending on your viewpoint, there is -- the value is its own minimum and maximum). You'd need to apply some further criteria in there for the results to be meaningful, and in doing so you'd probably need to be doing a join or a subselect with some criteria.