微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mysql-分组时mariaDB是否不支持SELECT语句中的功能依赖项?

我的sql语句中有GROUP BY的一些问题.

我正在使用mariaDB 10.1.17,并且注意到执行以下sql语句时出现错误

SELECT `pubs`.`ID` AS `ID`
    ,AVG(`reviews`.`atmosphere`) AS `average`
    ,`pubs`.`name` AS `name`
    ,`pubs`.`country` AS `country`
FROM `pubs`
LEFT JOIN `reviews` ON `pubs`.`ID` = `reviews`.`pub_ID`
GROUP BY `pubs`.`ID`
ORDER BY `average` DESC
    ,`reviews`.`date` DESC

我得到的错误

Syntax error or access violation: 1055 ‘pubreviews.pubs.name’ isn’t
in GROUP BY”

我的理解是,由于“功能依赖性”(一个ID映射到一个名称和国家/地区),因此不需要将这些列显式添加到group by语句中.

(我只有ONLY_FULL_GROUP_BY已打开)

这似乎暗示着here re MysqL 5.7.5

鉴于此错误消息.. mariaDB不实现此功能吗?

谢谢

解决方法:

根据mariadb文档,如果打开ONLY_FULL_GROUP_BY sql模式,则似乎不考虑功能依赖性.

关于ONLY_FULL_GROUP_BY sql模式的文档说:

For SELECT … GROUP BY queries, disallow SELECTing columns which are not referred to in the GROUP BY clause, unless they are passed to an aggregate function like COUNT() or MAX(). Produce a 1055 error.

因此,没有功能依赖的提示.

我还检查了文档中关于group by子句的内容

If you select a non-grouped column or a value computed from a non-grouped column, it is undefined which row the returned value is taken from. This is not permitted if the ONLY_FULL_GROUP_BY sql_mode is used.

同样,没有功能依赖的提示.

以上内容适用于mariadb版本10.1.18和10.2.2.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐