文章详情页
mysql - 这条sql语句为什么加上where就报错?
浏览:223日期: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)取得别名,数据库表字段本身没有这列吧。
查询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是等效的,不能重复,直接去掉where
相关文章:
1. javascript - sublime怎么支持webp的浏览?2. javascript - nginx 反向代理 js跨域问题?3. javascript - sublime已经安装了babel插件和sublimelinter-jshint为什么还是显示es6语法错误?4. nginx 80端口反向代理多个域名,怎样隐藏端口的?5. javascript - 图片能在网站显示,但控制台仍旧报错403 (Forbidden)6. python - pig latin问题 总是出现list/string index out of range7. html5 - 为什么浏览器可以显示HTML文档中未被定义的标签?8. css3 - img垂直水平居中问题9. 为什么标题文字前面加的小色块标识不显示10. javascript - angularJS select标签问题
排行榜

网公网安备