msyql 8.0.23 GROUP BY 后查询属性报错

分组过后的属性查询报错

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘wdf_bpm.wdf_monitor_type_item.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

错误原因

原因是mySql的8.几的某个版本 only_full_group_by设置又更改,所以GROUP BY要符合only_full_group_by的设置。

解决方法

在要查询的每个属性用 any_value()进行包裹

// 这是错误的查询
SELECT id,type_id FROM wdf_monitor_type_item GROUP BY type_id 
// 这是修改后的查询
SELECT any_value(id),any_value(type_id) FROM wdf_monitor_type_item GROUP BY type_id

你可能感兴趣的:(mysql,数据库)