mysql之ONLY_FULL_GROUP_BY 问题解决办法

大家在对数据表进行分组查询的时候肯定遇到过类似于这样的问题:
select username,age from users group by age;
然后mysql 就报错:
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mytest.users.username' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
大致的意思就是你必须将所要查询的username,age都进行分组操作才可以....所以就必须这样
select username,age from users group by age,username;才能通过编译,但这样就失去了分组本来的意义
因此我们通过改变sql_mode='';来改变原来的sql_mode='ONLY_FULL_GROUP_BY';这样就可以了

猜你喜欢

转载自huyifan951124.iteye.com/blog/2314996