[SQL๋ฌธ์ œํ’€๊ธฐ - Advent of SQL 2025 ๐ŸŽ…] ๋„์‹œ๋ณ„ VIP ๊ณ ๊ฐ ์ฐพ๊ธฐ

silver's avatar
Dec 23, 2025
[SQL๋ฌธ์ œํ’€๊ธฐ - Advent of SQL 2025 ๐ŸŽ…] ๋„์‹œ๋ณ„ VIP ๊ณ ๊ฐ ์ฐพ๊ธฐ

๋ฌธ์ œ

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

MySQL, PostgreSQL, SQLite

with a as (select city_id, customer_id, sum(total_price)-sum(discount_amount) total_spent from transactions where not is_returned group by city_id, customer_id) select city_id, customer_id, total_spent from a where (city_id, total_spent) in (select city_id, max(total_spent) from a group by city_id) order by 1;
Share article

silver