SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'demo.o.title' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
#查询sql_mode
select @@global.sql_mode;
修改sql_mode值
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
第二种,
MySQL有any_value(field)函数,他主要的作用就是抑制ONLY_FULL_GROUP_BY值被拒绝
官方有介绍,地址:https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_any-value
我们可以把select语句中查询的属性(除聚合函数所需的参数外),全部放入any_value(field)函数中;
#例如:
select name,any_value(sex) from test_table group by name
这样sql语句不管是在ONLY_FULL_GROUP_BY模式关闭状态还是在开启模式都可以正常执行,不被mysql拒绝
总结:
我用第二种 成功了!!! 第一种没有测试 因为需要管理员超级权限 ,所以没试过,也不知道有没有副作用!
完结!