报错,> 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
错误:
mysql:
select * ,count(*)as count from app_cash_trans_log group by app_cash_trans_log.tran_code having count(*)>=(select pla_config.cfg_value from pla_config where pla_config.cfg_name='tranMaxContinuity') order by app_cash_trans_log.id desc limit 5
> 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'atmp_service.app_cash_trans_log.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
> 时间: 0.001s
原因:
在MySQL5.7之后,sql_mode中默认存在ONLY_FULL_GROUP_BY,SQL语句未通过ONLY_FULL_GROUP_BY语义检查所以报错。
ONLY_FULL_GROUP_BY:ONLY_FULL_GROUP_BY要求select语句中查询出来的列必须是明确的(其他语句也是一样)。
以SQL语句select columes from table group by list为例:columns必须是聚集函数或者在group by后的表达式list中,并且list中必须包含主键,否则也会报错。
insert、update、delete语句都会报错(但不影响SQL语句的执行),因为这三种语句执行之前也会执行查询操作。
以主键为id的表为例:
SELECT count(1) FROM customer GROUP BY `name`;该SQL执行成功,因为count是聚集函数;
SELECT * FROM customer GROUP BY `name`;该SQL执行失败,因为*中包含主键id,而group by后的表达式中并没有包含id
SELECT name FROM customer GROUP BY `name`;该SQL执行成功,因为name包含在group by后的表达式中
SELECT name, contact FROM customer GROUP BY `name`;该SQL执行失败,因为contact没有包含在group by后的表达式中
解决方法1:
修改mysql配置去掉ONLY_FULL_GROUP_BY
select @@sql_mode
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'
解决方法2:
修改sql语句为
select tran_code,any_value(tran_name)as tran_name ,any_value(tran_date) as tran_date ,any_value(tran_time) as tran_time,any_value(id) as id,count(tran_code)as count
from app_cash_trans_log
group by tran_code
having count >=(select pla_config.cfg_value from pla_config where pla_config.cfg_name='tranMaxContinuity')
order by id desc limit 5;
报错,> 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column相关推荐
- 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'cre
sql语句 SELECT * FROM t_company_change_log WHERE company_id='257949626441666560' AND rec_status='N' GR ...
- mysql 报错解决思考Expression #5 of SELECT list is not in GROUP BY clause and contains nonaggregated column
mysql报错: [Err] 1055 - Expression #5 of SELECT list is not in GROUP BY clause and contains nonaggrega ...
- MySQL Expression 2 of SELECT list is not in GROUP BY clause and contains nonaggregated column yous
MySQL:Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'yous ...
- 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 conta ...
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.
安装了mysql5.7,用group by 查询时抛出如下异常: Expression #3 of SELECT list is not in GROUP BY clause and contains ...
- Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column
mysql 5.7 以上版本默认开启 ONLY_FULL_GROUP_BY: 在这个模式下,我们使用分组查询时,出现在select字段后面的只能是group by后面的分组字段,或使用聚合函数包裹着的 ...
- mysql报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
原因: https://blog.csdn.net/fansili/article/details/78664267 解决办法: 1:查看mysql配置文件位置 [root@localhost ~]# ...
- 解决SELECT list is not in GROUP BY clause and contains nonaggregated column..
问题描述 在一次zabbix的mysql库中写联合查询语句时报错 1055 - Expression #1 of SELECT list is not in GROUP BY clause and c ...
- 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains解决
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'btc ...
最新文章
- Angular学习心得之directive——require选项的细节
- 解决不是有效的win32应用程序
- 微信小程序自定义状态栏
- JSFL 获取当前脚本路径,执行其他脚本
- vagrant网站中box下载方法
- 和bmc_热固性BMC的注塑成型介绍
- wx2540h配置教程_H3C无线AP控制器EWP-WX2540H 无线AP 无线云台控制器 无线控制器
- 网页上使用按键代替鼠标点击按钮
- 机器人焊枪动作与编程实验_工业机器人编程实验.doc
- Iexplore.exe[XXXX]中发生未处理的win32异常”解决办法
- 关键词热度分析工具_不懂亚马逊关键词分析怎么办?10款超好用的亚马逊运营必备关键词研究分析工具,建议收藏!...
- 台湾省应广科技PMS150C纯IO PWM单片机MCU
- Technical support of ZYC-Roll Book
- mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
- Markdown / KaTex数学公式汇总
- 数据挖掘实战—餐饮行业的数据挖掘之挖掘建模
- 2019届高二(上)12月月考试题(文科)
- Python之Scrapy爬虫(热门网站数据爬取)
- Best Paper一作:所有实习经历都是有意义的
- [简单]代码片段_3
热门文章
- 能够让机器狗学会灭火, ModelArts3.0让AI离我们又近一步
- 【华为云技术分享】云图说|人工智能新科技—文字识别服务
- 【Angular专题】——【译】Angular中的ForwardRef
- Spark之SparkSQL实战
- ZooKeeper的安装和API
- LaTeX设置参考文献条目行距以及条目内行距的方法
- 计算机图形学E2——OpenGL Bresenham算法画直线
- 基于android的视频播放器,基于Android的视频播放器的设计与实现-.doc
- CMD执行命令出现NOMALY: meaningless REX prefix used以及IDEA提示Cannot run git问题解决
- Nginx代理介绍、安装及配置详解