inblog logo
|
silver
    SQL๋ฌธ์ œํ’€๊ธฐ

    [SQL๋ฌธ์ œํ’€๊ธฐ - Advent of SQL 2025 ๐ŸŽ…] ๋‘ ๋Œ€ํšŒ ์—ฐ์†์œผ๋กœ ์ถœ์ „ํ•œ ๊ธฐ๋ก์ด ์žˆ๋Š” ๋ฐฐ๊ตฌ ์„ ์ˆ˜

    silver's avatar
    silver
    Dec 09, 2025
    [SQL๋ฌธ์ œํ’€๊ธฐ - Advent of SQL 2025 ๐ŸŽ…] ๋‘ ๋Œ€ํšŒ ์—ฐ์†์œผ๋กœ ์ถœ์ „ํ•œ ๊ธฐ๋ก์ด ์žˆ๋Š” ๋ฐฐ๊ตฌ ์„ ์ˆ˜
    Contents
    ๋ฌธ์ œ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์˜ค๋‹ต๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์ •๋‹ต

    ๋ฌธ์ œ

    solvesql.com
    solvesql.com
    https://solvesql.com/problems/volleyball-players-in-two-consecutive-olympics/

    ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์˜ค๋‹ต

    : ์–ด๋–ค ์„ ์ˆ˜๊ฐ€ 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.id
    Share article

    silver

    RSSยทPowered by Inblog