当前位置:   article > 正文

MYSQL错误this is incompatible with sql_mode=only_full_group_by完美解决方案_mysql this is incompatible

mysql this is incompatible


1.需要用到group by语句。
但是,如果mysql是高版本,当执行group by时,select的字段不属于group by的字段的话,sql语句就会报错。报错信息如下:

  1. SELECT
  2. sce.id,sce.event_date,sc.build_area_type,sce.event_content,sce.event_number,sce.event_status,sce.event_prove,sce.event_recovery_date
  3. FROM
  4. safety_camera_event sce
  5. LEFT JOIN
  6. safety_camera sc
  7. ON
  8. sce.camera_id = sc.id
  9. AND
  10. sc.valid = 1
  11. WHERE
  12. sce.valid = 1
  13. AND
  14. sce.event_status = 0
  15. GROUP BY sc.build_area_type
  16. ORDER BY sce.event_date DESC

报错内容

 SELECT list is not in GROUP BY clause and contains nonaggregated column 'zd-internet.sce.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT list is not in GROUP BY clause and contains nonaggregated column 'zd-internet.sce.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

2.解决方法

在mysql的配置文件加配置

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

3.解决的结果

 

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号