Mysql8.0.16 only_full_group_by

【1】Mysql8.0.16 關於only_full_group_by問題sql

應公司業務的需求,安裝了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;

在新的服務器上跑出了這個錯誤:session

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_bythis

經查詢,默認開啓了only_full_group_by選項。spa

【2】解決方案code

想辦法關閉該選項便可。blog

注意:Mysql8.0.16版本有個現象:it

session sql_mode的值是空io

SHOW VARIABLES LIKE '%sql_mode%'; 

即利用如上SQL命令查詢的sql_mode值爲空。class

可是 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.

順序 選擇 循環 總結

相關文章
相關標籤/搜索