작성
·
437
0
-- 3. 평균 학점이 3.5미만인 학생은?
SELECT students.nickname AS "닉네임", ROUND(AVG(grade_points.point),2) AS "평균 학점"
FROM students
JOIN grades ON grades.student_id = students.id
JOIN grade_points ON grade_points.grade = grades.grade
GROUP BY students.nickname
HAVING 3.5 > AVG(grade_points.point)
;
-- 서브 쿼리 이용 답
SELECT students.nickname AS "닉네임", avg_grade_point.round AS "평균 학점"
FROM students
JOIN (-- 학생별_평균_학점
SELECT student_id, ROUND(AVG(point), 2)
FROM grades
JOIN grade_points ON grade_points.grade = grades.grade
GROUP BY student_id
HAVING AVG(point) < 3.5
) AS avg_grade_point ON avg_grade_point.student_id = students.id
;
서브 쿼리를 이용하려고 생각하는 게 좋을까요?
단순히 JOIN만 사용해서 할 수 있으면 JOIN만 써도 괜찮을까요..?
현업에서는 어떤 걸 더 많이 쓰게 될지 궁금합니다!
답변 1
0