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
效果图
解析:讲查询数量的语句结果作为外联表和主表关联。
新知识:askId 查询ID个数 group by askId 通过id分组
补充内容:
LEFT JOIN class_teaching E ON E.classCode = A.classCode
WHERE
E.teacherId = 1
1可用teacherModel.get("id")替换
补充内容为查询改教师教学班级的信息
以上内容为个人学习笔记,不保证准确性与简洁性