文章詳情頁
mysql - 這條sql語句為什么加上where就報錯?
瀏覽:103日期:2022-06-17 09:07:17
問題描述
這條SQL
SELECT *,SUM(tuanke_time.time) AS total_time FROM `tuanke_time` LEFT JOIN tuanke_student ON tuanke_student.Sid = tuanke_time.studentID WHERE total_time > 100GROUP BY tuanke_time.studentID
加上where就報錯說不存在total_time列,但是我看了明明存在啊
問題解答
回答1:total_time 是你給SUM(tuanke_time.time)取得別名,數(shù)據(jù)庫表字段本身沒有這列吧。
查詢total_time > 100,你可以試試
SELECT *FROM `tuanke_time` LEFT JOIN tuanke_student ON tuanke_student.Sid = tuanke_time.studentID GROUP BY tuanke_time.studentID having SUM(tuanke_time.time) > 100;回答2:
total_time是你在查詢輸出列中定義的,原來的表中沒有這個列。
回答3:外連接中on 和where是等效的,不能重復(fù),直接去掉where
上一條:sqlserver - mysql如何查詢多列重復(fù)的數(shù)據(jù)個數(shù)?下一條:mysql億級數(shù)據(jù)的標(biāo)簽數(shù)據(jù)庫如何正確建索引進(jìn)行模糊查詢
相關(guān)文章:
1. javascript - node.js服務(wù)端渲染解疑2. javascript - 求助關(guān)于js正則問題3. html5 - 如何解決bootstrap打開模態(tài)modal窗口引起頁面抖動?4. javascript - 求助這種功能有什么好點(diǎn)的插件?5. objective-c - ios百度地圖定位問題6. 微信開放平臺 - Android調(diào)用微信分享不顯示7. html - css 如何添加這種邊框?8. html5 - rudy編譯sass的時候有中文報錯9. javascript - 關(guān)于定時器 與 防止連續(xù)點(diǎn)擊 問題10. 為何 localStorage、sessionStorage 屬于html5的范疇,但是為何 IE8卻支持?
排行榜

熱門標(biāo)簽