多表联查统计数字
SQL语句:
select A.*, B.count1, C.count2, D.count3 from task A
left join (select count(id) count1, askId from task_upload group by askId) B on A.id=B.askId
left join (select count(id) count2, askId from task_upload where state=1 group by askId) C on A.id=B.askId left join (select count(id) count3, askId from task_upload where state=2 group by askId) D on A.id=B.askId
sql left join 多表连接效果图
解析:讲查询数量的语句结果作为外联表和主表关联。
新知识:askId 查询ID个数 group by askId 通过id分组
补充内容:
LEFT JOIN class_teaching E ON E.classCode = A.classCode
WHERE
1可⽤("id")替换
补充内容为查询改教师教学班级的信息
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论