[mysql] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'lo
2017-01-23 14:01
1501 查看
执行SQL:
SELECT login_name,login_ip,sex FROM tank_admin GROUP BY login_name ;
时抛出异常。
这个sql语句违背了sql_mode=only_full_group_by 。
先看看这个sql_mode=only_full_group_by是个什么意思:
(摘自官网文档)
Reject queries for which the select list,
dependent on (uniquely determined by)
As of MySQL 5.7.5, the default SQL mode includes
functional dependency and
see the MySQL 5.6 Reference Manual.)
A MySQL extension to standard SQL permits references in the
this extension, thus requiring the
whether
For additional discussion and examples, see Section 13.20.3, “MySQL Handling of GROUP BY”.
来源链接:
http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_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';
去掉ONLY_FULL_GROUP_BY即可正常执行sql.
SELECT login_name,login_ip,sex FROM tank_admin GROUP BY login_name ;
时抛出异常。
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'loser.tank_admin.login_ip' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这个sql语句违背了sql_mode=only_full_group_by 。
先看看这个sql_mode=only_full_group_by是个什么意思:
(摘自官网文档)
ONLY_FULL_GROUP_BY
Reject queries for which the select list,
HAVINGcondition, or
ORDER BYlist refer to nonaggregated columns that are neither named in the
GROUP BYclause nor are functionally
dependent on (uniquely determined by)
GROUP BYcolumns.
As of MySQL 5.7.5, the default SQL mode includes
ONLY_FULL_GROUP_BY. (Before 5.7.5, MySQL does not detect
functional dependency and
ONLY_FULL_GROUP_BYis not enabled by default. For a description of pre-5.7.5 behavior,
see the MySQL 5.6 Reference Manual.)
A MySQL extension to standard SQL permits references in the
HAVINGclause to aliased expressions in the select list. Before MySQL 5.7.5, enabling
ONLY_FULL_GROUP_BYdisables
this extension, thus requiring the
HAVINGclause to be written using unaliased expressions. As of MySQL 5.7.5, this restriction is lifted so that the
HAVINGclause can refer to aliases regardless of
whether
ONLY_FULL_GROUP_BYis enabled.
For additional discussion and examples, see Section 13.20.3, “MySQL Handling of GROUP BY”.
来源链接:
http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_only_full_group_by
MySQL Handling of 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';
去掉ONLY_FULL_GROUP_BY即可正常执行sql.
相关文章推荐
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sss
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column '
- mysql:Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- mysql错误:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ga
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.
- Mysql解决SELECT list is not in GROUP BY clause and contains nonaggregated column 问题
- Docker安装MySQL遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- [Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_by
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated
- [Err] 1055 - Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonag
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- [Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题