我在输入SQL语句
SELECT grade FROM sy_epwk GROUP BY grade='一品';
时mysql报错:ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'pro_data.sy_epwk.grade' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
各种百度寻找解决方法,了解到使用group by select中要有聚合函数,并且所有非聚合函数的列都要现现在group by 后
可是我是个新手,理解不了这句话的含义。试过百度上的设置sql_mode,可是设置了很久都报错。于是自己查看官方文档
先在mysql客户端输入show variables like 'sql_mode';查看当前的sql_mode:
我发现只要把开头的ONLY_FULL_GROUP_BY去掉就可以了
于是输入 set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
最后再运行SELECT grade FROM sy_epwk GROUP BY grade='一品';
执行成功