Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘studentsc

 

目录

问题:

原因:

解决:

 修改配置文件:

1.找到MySQL安装目录下,找对my.ini(windows系统)或者my.cnf(linux系统)配置文件,并打开;

2.添加如下代码:   (注意:代码一定要放在[mysqld]节点最后一行,别放错了哦!)

3.保存配置文件,重启服务器。(一定要重启MySQL服务器哦!)

 查询成功:


问题:

在navcat上创建视图后,执行:

SELECT * FROM student_info;

后出现一下错误: 

Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'studentscoremanagement.c.cname' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因:

        MySQL 5.7.5及以上功能依赖检测功能。如果启用了ONLY_FULL_GROUP_BY SQL模式(默认情况下),MySQL将拒绝选择列表,HAVING条件或ORDER BY列表的查询引用在GROUP BY子句中既未命名的非集合列,也不在功能上依赖于它们。(5.7.5之前,MySQL没有检测到功能依赖关系,默认情况下不启用ONLY_FULL_GROUP_BY。有关5.7.5之前的行为的说明,请参见“MySQL 5.6参考手册”。)

解决:

  • 一劳永逸的方法

 修改配置文件:

1.找到MySQL安装目录下,找对my.ini(windows系统)或者my.cnf(linux系统)配置文件,并打开;

Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘studentsc_第1张图片

2.添加如下代码:   (注意:代码一定要放在[mysqld]节点最后一行,别放错了哦!)

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

如果你的版本是8.0以上的直接删除 :ONLY_FULL_GROUP_BY  即可

 

3.保存配置文件,重启服务器。(一定要重启MySQL服务器哦!)

(本人是在windows系统下亲测有效,linux没试)

重启步骤:

  • win+R  输入cmd
  • 然后输入: taskmgr   敲回车进入任务管理栏

    Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘studentsc_第2张图片

  •  点击服务找到Mysql后右键,点击重新启动即可

 Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘studentsc_第3张图片

 查询成功:

Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘studentsc_第4张图片

 

你可能感兴趣的:(日常错误解决,配置文件,数据库学习,数据库,sql)