Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

场景

安装了mysql5.7,用group by 查询时抛出如下异常:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

解决

如果以及将mysql配置进了环境变量,打开cmd,输入

mysql -u root -p

-u 后面是代表root,-p后面加上自己的root密码,如果没有密码直接回车

如果是没有将mysql配置进环境变量,则需要进入到mysql的安装目录下的bin目录,即有mysql.exe的目录。

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column_第1张图片

然后按住shift在此处打开命令窗口。

输入:

mysql -u root -p

如果root 有密码,在后面加上密码,如果没有密码,按回车提示输入密码后直接回车即可。

登录进mysql后,输入:

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';

 

然后再输入:

set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

 

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