MySQL使用group by 報this is incompatible with sql_mod

下面是employee表的所有數據。
MySQL使用group by 報this is incompatible with sql_mod
使用group by 分組查詢報錯this is incompatible with sql_mode=only_full_group_by
MySQL使用group by 報this is incompatible with sql_mod
查看sql_model參數發現:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

MySQL使用group by 報this is incompatible with sql_mod

ONLY_FULL_GROUP_BY選項開啓,那麼在使用group by時候, 只能select查詢group by後面的選項,或者使用聚合函數。
只查詢group by後面的列:
MySQL使用group by 報this is incompatible with sql_mod
使用聚合函數:
MySQL使用group by 報this is incompatible with sql_mod
但以上兩種方法不推薦!!!
推薦解決方法:
1.臨時,重啓mysql會失效
MySQL使用group by 報this is incompatible with sql_mod
set @@GLOBAL.sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
2.修改/etc/my.cnf
[mysqld]
加一行
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
重啓MySQL即可生效。
MySQL使用group by 報this is incompatible with sql_mod

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章