赞
踩
SHOW VARIABLES LIKE 'sql_mode';
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
[mysqld]
#set the SQL mode to strict
#sql-mode="modes..."
sql-mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
SELECT name, dept, MAX(age) FROM employee GROUP BY dept;
MySQL5.7中执行 : 以上查询语句在 “ONLY_FULL_GROUP_BY
” 模式下查询出错,因为 select
子句中的 name
列并没有出现在group by
子句中,也没有出现在函数中
MySQL5.5中执行 : 在非 “ONLY_FULL_GROUP_BY
” 模式下可以正常执行,但是得到的是错误的结果
SELECT e.*
FROM employee e
INNER JOIN
(SELECT dept, max(age) age FROM employee GROUP BY dept) AS maxage
ON e.dept = maxage.dept AND e.age = maxage.age
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。