- 使用select * from 表 group by 字段 時報錯
錯誤信息說明:sql
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'haha_db.staff.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by數據庫
- 只須要執行下面的SQL語句來更改sql mode便可
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY',''));this
注意在執行上述語句後須要從新鏈接數據庫spa
- 從新創建鏈接後再次執行SQL語句,顯示執行成功
說明:group by默認顯示的是每一組找到的第一條信息it