๋ฌธ์
https://leetcode.com/problems/find-students-who-improved/
์ฝ๋ ๋ต์
with result as (
select
student_id,
subject,
lag(score) over (partition by student_id, subject order by exam_date) as first_score,
score as latest_score
from scores
)
select *
from result
where latest_score > first_score
-- 6๋ถ
๋ฌธ์ ํ์ด
- WINDOW FUNCTION over (partition by ๊ธฐ์ค 1, ๊ธฐ์ค 2)
์๋ก ์๊ฒ ๋ ์ฌ์ค
group by๋ 2๊ฐ์ ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก ๊ทธ๋ฃนํ ๊ฐ๋ฅํ๋ฏ์ด
partition by๋ 2๊ฐ์ ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก ํํฐ์ ์ ๋๋๋ ๊ฒ ๊ฐ๋ฅํ๋ค!
๋๋ ์
์์
