[SQL๋ฌธ์ ํ๊ธฐ - Advent of SQL 2025 ๐ ] ๋ ๋ํ ์ฐ์์ผ๋ก ์ถ์ ํ ๊ธฐ๋ก์ด ์๋ ๋ฐฐ๊ตฌ ์ ์
Dec 09, 2025
๋ฌธ์
๋ด๊ฐ ์์ฑํ ์ค๋ต
: ์ด๋ค ์ ์๊ฐ 2000๋
๊ณผ 2008๋
์๋ง ์ถ์ ํ๋๋ผ๋, ๊ทธ ์ฌ์ด์ ํ๊ตญ ์ฌ์ ๋ฐฐ๊ตฌ ์ถ์ ์ด ์์ผ๋ฉด ์ฐ์์ผ๋ก ์กํ์ง๋ง ์ค์ ๋ก๋ 8๋
๊ฐ๊ฒฉ์ด๋ผ ์ฐ์ ์ฌ๋ฆผํฝ์ด ์๋๋ค
with a as (select r.athlete_id, g.year, dense_rank() over(order by g.year) dr
from records r
join games g on r.game_id = g.id
where event_id in (select id
from events
where event = 'Volleyball Women''s Volleyball')
and team_id in (select id from teams where team = 'KOR')
and r.sex = 'F')
select distinct a.athlete_id id, c.name
from a a
join a b on a.dr+1 = b.dr and a.athlete_id = b.athlete_id
join athletes c on a.athlete_id = c.id๋ด๊ฐ ์์ฑํ ์ ๋ต
MySQL, SQLite, PostgreSQL
with a as (select id,dense_rank() over(order by year) dr from games where season = 'Summer'),
b as (select r.athlete_id, a.dr
from records r
join a a on r.game_id = a.id
where event_id in (select id
from events
where event = 'Volleyball Women''s Volleyball')
and team_id in (select id from teams where team = 'KOR'))
select distinct a.athlete_id id, c.name
from b a
join b b on a.dr+1 = b.dr and a.athlete_id = b.athlete_id
join athletes c on a.athlete_id = c.idShare article