有这么一个SQL看似没什么问题, 但是他报错了😂, 为什么呢? 接着往下看
select DISTINCT name, age, sex FROM student ORDER BY birthday DESC
在MySQL5.7的语法会更加严格, DISTINCT和ORDER BY同时使用时, 这两个都会进行排序的处理, 在DISTINCT处理完后, 再用ORDER BY排序将找不到需要排序的字段.
解决方案一
1.在my.ini配置文件中加入以下配置
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
2.重启MySQL服务
net stop mysql服务名称
net start mysql服务名称
解决方案二
ORDER BY 的字段在SELECT中也要有
select DISTINCT name, age, sex, birthday FROM student ORDER BY birthday DESC
这有就没问题了😉