SELECT COURSECODE, COUNT(user:_ID) FROM TABLE1, TABLE3
WHERE
TABLE3.user:_ID = TABLE2.course_user:_ID
AND
TABLE2.ID_COURSE = TABLE1.ID_USER
GROUP BY COURSECODE
HAVING COUNT(TABLE2.ID_USER) < 30
SELECT c.COURSECODE, count(u.id) as userCount
FROM course_user cu JOIN course c on (c.id = cu.id_course) JOIN user u on (u.id = cu.id_user)
GROUP BY c.COURSECODE
HAVING userCount < 30;
select Course.COURSECODE, count(course_user.ID_USER) from course
join course_user on course_user .ID_COURSE = course._ID
group by Course.COURSECODE
having count(course_user.ID_USER) < 30
SELECT c.COURSECODE
FROM course_user cu
LEFT JOIN course c on (c.id = cu.id_course)
LEFT JOIN user u on (u.id = cu.id_user)
GROUP BY c.COURSECODE
HAVING count(cu.id_user) < 30
4条答案
按热度按时间5vf7fwbs1#
这里有一个想法:
请避免使用无意义或混淆的名称。如
user: _ID
,ID_USER
,course_user: _ID
有关此查询的更多信息,我建议您查看:计数文档
按文档分组
有文件
wj8zmpe12#
试试这个:
ars1skjm3#
看看having子句:http://www.mysqltutorial.org/mysql-having.aspx
像这样:
z31licg04#
您可以使用: