[SQL๋ฌธ์ œํ’€๊ธฐ - Advent of SQL 2025 ๐ŸŽ…] ์ดํ‹€ ์—ฐ์† ๋ฏธ์„ธ๋จผ์ง€๊ฐ€ ๋‚˜๋น ์ง„ ๋‚ 

silver's avatar
Dec 07, 2025
[SQL๋ฌธ์ œํ’€๊ธฐ - Advent of SQL 2025 ๐ŸŽ…] ์ดํ‹€ ์—ฐ์† ๋ฏธ์„ธ๋จผ์ง€๊ฐ€ ๋‚˜๋น ์ง„ ๋‚ 

๋ฌธ์ œ

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

์• ์ดˆ์— 2022๋…„ ์„œ์šธ์ˆฒ ๋Œ€๊ธฐ์ธก์ •์†Œ์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์ด๋ฏ€๋กœ ๋‚ ์งœ์™€ ์œ„์น˜ ์กฐ๊ฑด์„ ๋”ฐ๋กœ ์•ˆ ๋„ฃ์–ด๋„ ๋œ๋‹ค.
notion image

MySQL

select a.measured_at date_alert from measurements p right join measurements d on date_add(p.measured_at,interval 1 day) = d.measured_at right join measurements a on date_add(d.measured_at,interval 1 day) = a.measured_at where -- (year(p.measured_at) = '2022' and year(a.measured_at) = '2022') and (p.pm10 < d.pm10 and d.pm10 < a.pm10) and a.pm10 >= 30 order by 1;

SQLite

select a.measured_at date_alert from measurements p right join measurements d on date(p.measured_at,'+1 day') = d.measured_at right join measurements a on date(d.measured_at,'+1 day') = a.measured_at where -- strftime('%Y',p.measured_at) = '2022' and strftime('%Y',a.measured_at) = '2022' and (p.pm10 < d.pm10 and d.pm10 < a.pm10) and a.pm10 >= 30 order by 1;

PostgreSQL

: date์—๋Š” ํ•˜๋ฃจ ๋”ํ•  ๋•Œ๋Š” ๊ทธ๋ƒฅ +1ํ•˜๋ฉด ๋˜๊ณ  datetime์—๋Š” + interval โ€˜1 dayโ€™ ํ•˜๋ฉด ๋จ
select a.measured_at date_alert from measurements p right join measurements d on p.measured_at+1 = d.measured_at right join measurements a on d.measured_at+1 = a.measured_at where -- (to_char(p.measured_at,'yyyy') = '2022' and to_char(a.measured_at,'yyyy') = '2022') and (p.pm10 < d.pm10 and d.pm10 < a.pm10) and a.pm10 >= 30 order by 1;
Share article

silver