gpt4 book ai didi

mysql - 普通列后跟聚合函数但不在分组依据中

转载 作者:可可西里 更新时间:2023-11-01 07:48:16 25 4
gpt4 key购买 nike

我知道只有在包含它们的 Group By 之后才允许后跟聚合函数的普通列。
但是为什么下面的工作?

mysql> select payee,sum(amount) from checks;  
+---------+-------------+
| payee | sum(amount) |
+---------+-------------+
| Ma Bell | 893.76 |
+---------+-------------+
1 row in set (0.00 sec)

最佳答案

This behavior is an "extension" to MySql :

MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause.

然而,This behavior is actually a configurable setting in MySql :

ONLY_FULL_GROUP_BY

Do not permit queries for which the select list or (as of MySQL 5.1.10) HAVING list refers to nonaggregated columns that are not named in the GROUP BY clause.

最好尊重 group by 并添加所有非聚合列,特别是如果有一天您可能会迁移到具有 的服务器>ONLY_FULL_GROUP_BY 开启。

关于mysql - 普通列后跟聚合函数但不在分组依据中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14863731/

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