.btnLink{
background:none!important;
border:none;
padding:0!important;
font-family:arial,sans-serif; /*input has OS specific font-family*/
color:#069;
text-decoration:underline;
cursor:pointer;
}
使用此查询,我如何根据内部查询的courseID计数来订购结果
答案 0 :(得分:3)
加入一个计算入学次数的派生表:
SELECT c.*, t.enrolment_count
FROM Course c
JOIN (
Select CourseID, count(*) as enrolment_count
FROM Enrolment
GROUP BY CourseID
HAVING COUNT(CourseID) > 1
) t on t.courseid = c.courseid
order by t.enrolment_count;
通常,IN
和联接不一定会被替换,因为它们正在做不同的事情。在这种情况下,连接将与group by
保证每个courseid
在派生表中唯一的保证相同,因此不会增加结果中的总行数。