我有这个查询,我想优化它。我使用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
答案 0 :(得分: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)