在严格模式下GROUP BY 报错,
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hd_groupbuying_help.help_state' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
测试得到结论:
mysql的 sql_mode=only_full_group_by 模式下group by 分组查询的select字段 ,除了group by 的字段之外其他的字段都要有聚合函数包裹,
如:sum、avg、max、min、count。
mysql从5.7以后,默认开启group by的严格模式。如果错误号是1055,处理方式可以2种,
1)更改my.cnf(windows下是my.ini)中的sql_mode参数,去掉:only_full_group_by。
2)修改SQL语句,查询的列和group by的列,需要一致(主键可以忽略、用了函数的列可以忽略)