course
id | name | description
course_assignments
id |course_id | description|...
user_assignments
id| c_assignment_id | u_date
我想要返回的是课程ID,COUNT(当然是作业),COUNT(用户课程作业)
目前,我懒得使用多个子查询,然后将结果加入course_id。
SELECT c.id, a.total, u.submitted
FROM course
JOIN(SELECT course_id, COUNT(*) as total FROM course_assignments
GROUP_BY course_id) as a ON a.course_id=c.id
JOIN (SELECT c_assignment_id, COUNT(*) as complete
FROM course_assignments GROUP_BY c_assignment_id) as u ON
a.id=u.c_assignment_id
更聪明的方法是什么?