Mysql5.7.20使用group by查詢(select *)時出現錯誤--修改sql mode


  • 使用select * from 表 group by 字段 時報錯

  

  錯誤信息說明:

  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',''));

   

  注意在執行上述語句后需要重新連接數據庫

 

  • 重新建立連接后再次執行SQL語句,顯示執行成功

   

  說明:group by默認顯示的是每一組找到的第一條信息

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM