galleryview翻译mysql5.7倒序后分组_mysql5.7先排序ORDERBY,后分组
GROUPBY
关于mysql5.7 排序ORDER BY ,分组 GROUP BYimfilter函数用法
amaze ui中文文档安装最新的MySQL5.7,发现之前group by语句报错,发现mysql5.7 默认开启only_full_group_by 模式,
错误信息如下:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
'der_no' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
解决⽅式:
year函数的使用方法及实例第⼀种⽅式:直接修改配置⽂件删掉only_full_group_by
自学程序代码教程第⼆种⽅式:
set @@global.sql_mode
='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_EN
上⾯sql改变全局sql_mode,新建的数据库有效
set sql_mode
='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_EN
这条sql修改已存在的数据库sql_mode
mysql语句顺序然后开始执⾏先排序后分组的sql
SELECT * FROM
(SELECT * FROM users ORDER BY user_id DESC) temp
GROUP BY temp. user_id
发现排序居然没有⽣效,顿时很惊讶
explain 查看执⾏计划,发现在没有 limit 的情况,会少了⼀个derived 操作,mysql会认为这时候不需要排序,内部做了优化,所以这种情况下
加limit限制就可以了,如下(limt 后的⾏数 可以作为参数传⼊):
SELECT * FROM
(SELECT * FROM users ORDER BY user_id DESC limit 100) temp
GROUP BY temp. user_id
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论