日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql group by 规则_MySQL 中关于 GROUP BY 的问题

發布時間:2023/12/19 数据库 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql group by 规则_MySQL 中关于 GROUP BY 的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在準備開發博客系統的前期,觀摩了一位大佬的源碼:http://pan.baidu.com/s/1eRfrsAm

這是16年的一份博客源碼系統,但是在測試部署時發現了一個問題不解!!!

后網上資源解析說與Group by分組條件相關,本人對數據庫mysql也是有所學習,但是在這種分組與排序中經常被難倒,于是乎寫下這篇,做為記錄

idea:控制臺server界面輸出:

十月 16, 2019 10:29:55 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc

嚴重: The web application [/Blog] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

十月 16, 2019 10:29:55 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc

嚴重: The web application [/Blog] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

[2019-10-16 10:29:55,151] Artifact Blog:war exploded: Error during artifact deployment. See server log for details.

十月 16, 2019 10:30:00 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory C:\Tomcat\apache-tomcat-7.0.67\webapps\manager

十月 16, 2019 10:30:00 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deployment of web application directory C:\Tomcat\apache-tomcat-7.0.67\webapps\manager has finished in 86 ms

tomcat log輸出:

org.springframework.jdbc.BadSqlGrammarException:

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_blog.t2.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

The error may exist in file Blog\target\Blog\WEB-INF\classes\com\java1234\mappers\BlogTypeMapper.xml]

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT t2.id,t2.typeName,COUNT(t1.id) AS blogCount FROM tblog t1 RIGHT JOIN tblogType t2 ON t1.typeId=t2.id GROUP BY t2.typeName order by t2.orderNo;

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_blog.t2.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_blog.t2.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

其實這邊idea已經很明顯的指出了是分組帶來的錯誤,在歲連表查詢過程中的t2名稱表的id查詢出錯

正規解釋:db_blog.t2.id 在 GROUP BY 中違背了 mysql 的規則。

select 字段必須都在 group by 分組條件內(含有函數的字段除外)。(如果遇到 order by 也出現這個問題,同理,order by 字段也都要在group by內 )

于是乎, GROUP BY 中加入 t2.id,成功解決問題。

SELECT

t2.id,

t2.typeName,

COUNT( t1.id ) AS blogCount

FROM

t_blog t1

RIGHT JOIN t_blogtype t2 ON t1.typeId = t2.id

GROUP BY

t2.typeName,

t2.id

ORDER BY

t2.orderNo;

如果這些還沒解析明白,可以去https://blog.csdn.net/u010429286/article/details/64444271 看看

總結

以上是生活随笔為你收集整理的mysql group by 规则_MySQL 中关于 GROUP BY 的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。