[SQL๋ฌธ์ ํ๊ธฐ - Advent of SQL 2025 ๐ ] 12์ ์ฐ์ ๊ณ ๊ฐ ์ฐพ๊ธฐ
Dec 03, 2025
๋ฌธ์
๋ด๊ฐ ์์ฑํ ์ ๋ต
๊ณตํต
select customer_id
from records
where order_date between '2020-12-01' and '2021-01-01'
group by customer_id
having sum(sales) >= 1000;๋ ์ง ๋ณํ ๋ฉ์๋ ๋ค๋ฆ
// MySQL
select customer_id
from records
where date_format(order_date,'%Y%m') = '202012'
group by customer_id
having sum(sales) >= 1000;
// PostgreSQL
select customer_id
from records
where to_char(order_date,'yymm') = '2012'
group by customer_id
having sum(sales) >= 1000;
// SQLite
select customer_id
from records
where strftime('%Y-%m',order_date) = '2020-12'
group by customer_id
having sum(sales) >= 1000;Share article