1

我有这个查询,我想优化它。我使用一个 SELECT 和一个子查询,如果可能的话,我只想使用一个 SELECT。

有人对此有任何想法吗?

先感谢您

SELECT c.*
FROM course AS c
JOIN student_course AS sc ON c.id = uc.course_id
WHERE sc.student_id = '5' AND c.level = (SELECT MAX(level) 
                                         FROM course  
                                         JOIN student_course ON c.id = sc.course_id)
GROUP BY c.category_id 
4

1 回答 1

3
SELECT c.*
FROM course AS c
JOIN student_course AS sc
ON c.id = sc.course_id
WHERE sc.student_id = '5' 
GROUP BY c.category_id 
having c.level = MAX(sc.level)
于 2012-11-30T12:15:05.217 回答