DQL
select courseId from score
GROUP BY courseId ORDER BY avg(result) desc limit 1;
select courseName '科目名称',department '系别',number'人数'from course
where id=(
select courseId from score
GROUP BY courseId ORDER BY avg(result)desc limit 1
);
select courseId from score
GROUP BY courseId ORDER BY avg(result) desc limit 1;
select courseName '科目名称',department '系别',number'人数'from course
where id in(
select courseId from score
GROUP BY courseId ORDER BY avg(result)desc
)
limit 3;
查询结果
总结:子查询,如果是多个结果查询用in查询,如果使用limit做限制,则需要写在父查询上。