mysql - 這條sql語句為什么加上where就報(bào)錯(cuò)?
問題描述
這條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就報(bào)錯(cuò)說不存在total_time列,但是我看了明明存在啊
問題解答
回答1:total_time 是你給SUM(tuanke_time.time)取得別名,數(shù)據(jù)庫(kù)表字段本身沒有這列吧。
查詢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是你在查詢輸出列中定義的,原來的表中沒有這個(gè)列。
回答3:外連接中on 和where是等效的,不能重復(fù),直接去掉where
相關(guān)文章:
1. 前端 - 關(guān)于img父容器的高度會(huì)比img的高度多幾像素的問題?2. debian - docker依賴的aufs-tools源碼哪里可以找到啊?3. dockerfile - [docker build image失敗- npm install]4. html5 - 自己的H5頁面如何集成支付寶支付5. php工具中的mysql還是5.1以下的,請(qǐng)問如何才能升級(jí)到5.1以上?6. css3 - 沒明白盒子的height隨width的變化這段css是怎樣實(shí)現(xiàn)的?7. javascript - 移動(dòng)端自適應(yīng)8. Mysql如何按照日期對(duì)比數(shù)據(jù),求SQL語句9. ios - 類似微博首頁,一張圖的時(shí)候是如何確定圖大小的?10. atom開始輸入!然后按tab只有空格出現(xiàn)沒有html格式出現(xiàn)
