当前位置:网站首页>“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
2022-04-23 06:09:00 【qq_15197419】
问题描述
sql:
SELECT ID ,COUNT(ID) as favoriteCount,productID FROM l_favorite GROUP BY productID
报错:
MySql.Data.MySqlClient.MySqlException:“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘lec.l_favorite.ID’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”
原因分析:
一开始感觉比较奇怪,在数据库管理工具里运行不报错,EF又会报错。而且有时报错,有时又不报。
我先是直接搜索了报错内容,然后一堆文章直接就写的,去掉mysql配置文件里的sql_mode=ONLY_FULL_GROUP_BY配置。
就很无语,报错原因不说,也不解决问题,直接就去解决产生报错的配置项,既然默认配置是这样,那肯定有它的道理,不要动不动就去改配置,这不是好习惯。
然后翻译了下这段英文,大概意思是说ID这个字段没有聚合。
唔…看了下sql,自己马虎了,多select了个ID字段,而分组字段又是productID 。导致数据库认为,把多个不同的ID聚合成同一个ID,是不合法的。
解决方案:
把select后面没有聚合的ID字段去掉就行了。
版权声明
本文为[qq_15197419]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_15197419/article/details/123400712
边栏推荐
- Android-Room数据库快速上手
- [recommendation for new books in 2021] professional azure SQL managed database administration
- oracle杀死正在执行的sql
- Oracle Job定时任务的使用详解
- 开篇:双指针仪表盘的识别
- iTOP4412 FramebufferNativeWindow(4.0.3_r1)
- Django::Did you install mysqlclient?
- Cause: dx. jar is missing
- Itop4412 surfaceflinger (4.4.4_r1)
- org. xml. sax. SAXParseException; lineNumber: 141; columnNumber: 252; cvc-complex-type. 2.4. a: Found element 'B
猜你喜欢
WebView displays a blank due to a certificate problem
[2021 book recommendation] practical node red programming
useReducer基本用法
【2021年新书推荐】Professional Azure SQL Managed Database Administration
ThreadLocal,看我就够了!
this. getOptions is not a function
Android interview Online Economic encyclopedia [constantly updating...]
Itop4412 LCD backlight drive (PWM)
基于BottomNavigationView实现底部导航栏
从0开始封装一套项目的网络请求框架
随机推荐
Recyclerview batch update view: notifyitemrangeinserted, notifyitemrangeremoved, notifyitemrangechanged
MySQL笔记5_操作数据
Django::Did you install mysqlclient?
第三篇:docker安装mysql容器(自定义端口)
中国各省会城市经纬度位置
Bottom navigation bar based on bottomnavigationview
Exception record-14
数据库的事务
Ffmpeg common commands
Itop4412 HDMI display (4.0.3_r1)
this.getOptions is not a function
发布自定义插件到本地服务器
Using queue to realize stack
MySQL notes 4_ Primary key auto_increment
[sm8150] [pixel4] LCD driver
【2021年新书推荐】Effortless App Development with Oracle Visual Builder
Oracle锁表查询和解锁方法
oracle分区的相关操作
MySQL笔记1_数据库
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation