赞
踩
1.需要用到group by语句。
但是,如果mysql是高版本,当执行group by时,select的字段不属于group by的字段的话,sql语句就会报错。报错信息如下:
- SELECT
- 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
- FROM
- safety_camera_event sce
- LEFT JOIN
- safety_camera sc
- ON
- sce.camera_id = sc.id
- AND
- sc.valid = 1
- WHERE
- sce.valid = 1
- AND
- sce.event_status = 0
- GROUP BY sc.build_area_type
- 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.解决的结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。