[SQL๋ฌธ์ ํ๊ธฐ - Advent of SQL 2025 ๐ ] ์ฐ๋๋ณ ์๋งค์ถ ๊ตฌํ๊ธฐ
Dec 19, 2025
๋ฌธ์
๋ด๊ฐ ์์ฑํ ์ค๋ต

PostgreSQL
: ์ถ๋ ฅ๋ ๋
๋๊ฐ ๋ฌธ์์ด์ด๋ผ์ ์ค๋ต์ฒ๋ฆฌ ๋๋ค.โ ์ซ์๋ก ์ถ๋ ฅํ๋ ์ ๋ต์ฒ๋ฆฌ ๋๋ค
select to_char(purchased_at,'yyyy') as year, sum(total_price)-sum(discount_amount) net_sales
from transactions
where not is_returned
group by to_char(purchased_at,'yyyy')
order by year;SQLite
: PostgreSQL์์ ๋
๋๋ฅผ ๋ฌธ์์ด๋ก ์ถ๋ ฅํด์ ์ค๋ต์ฒ๋ฆฌ ๋์ด ์ซ์๋ก ์ถ๋ ฅํ๋๋ฐ ์ค๋ต์ฒ๋ฆฌ ๋๋ค. โ ๋ฌธ์๋ก ์ฒ๋ฆฌํ๋ ์ ๋ต์ฒ๋ฆฌ ๋๋ค.
select strftime('%Y',purchased_at)+0 as year, sum(total_price)-sum(discount_amount) net_sales
from transactions
where not is_returned
group by strftime('%Y',purchased_at)+0
order by year;select cast(strftime('%Y',purchased_at) as integer) as year, sum(total_price)-sum(discount_amount) net_sales
from transactions
where not is_returned
group by cast(strftime('%Y',purchased_at) as integer)
order by year;๋ด๊ฐ ์์ฑํ ์ ๋ต
MySQL
select year(purchased_at) year, sum(total_price)-sum(discount_amount) net_sales
from transactions
where not is_returned
group by year(purchased_at)
order by year;PostgreSQL
select extract(year from purchased_at) as year, sum(total_price)-sum(discount_amount) net_sales
from transactions
where not is_returned
group by extract(year from purchased_at)
order by year;SQLite
select strftime('%Y',purchased_at) as year, sum(total_price)-sum(discount_amount) net_sales
from transactions
where not is_returned
group by strftime('%Y',purchased_at)
order by year;Share article