Mysql8.0.16 only_full_group_by

【1】Mysql8.0.16 关于only_full_group_by问题

应公司业务的需求,安装了Mysql8.0.16版本,原来在Mysql5.6版本执行无恙的SQL语句:

SELECT product_id, call_type, 
SUM(service_fee) AS un_total_fee, 
SUM(duration) AS total_duration, 
COUNT(*) AS total_times, source, 
SUM(np_fee) AS np_total_fee, 
NOW() AS current
FROM view_dat_sdr_201903 
WHERE product_id = '110119120' AND call_type & (4196288 + 63551) > 0
AND (ISNULL(reserve_00) OR reserve_00 = 0 OR reserve_00 = 2)
GROUP BY call_type;

在新的服务器上跑出了这个错误:

error : Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'billing.view_dat_sdr_201903.source' which is not functily dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

经查询,默认开启了only_full_group_by选项。

【2】解决方案

目标:想办法关闭该选项即可。

注意:Mysql8.0.16版本有个现象:

session sql_mode的值是空

SHOW VARIABLES LIKE '%sql_mode%'; 

即利用如上SQL命令查询的sql_mode值为空。

但是,global sql_mode的值非空。利用如下SQL命令查询:

SHOW GLOBAL VARIABLES LIKE '%sql_mode%'; 

sql_mode值如下:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

重置global sql_mode的值:

SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

执行后,遂验证,一切正常。

 

Good Good Study, Day Day Up.

顺序 选择 循环 总结

转载于:https://www.cnblogs.com/Braveliu/p/10796490.html

你可能感兴趣的:(Mysql8.0.16 only_full_group_by)