[SQL๋ฌธ์ ํ๊ธฐ - Advent of SQL 2025 ๐ ] A/B ํ ์คํธ๋ฅผ ์ํ ๋ฒํท ๋๋๊ธฐ 2
Dec 23, 2025
๋ฌธ์
๋ด๊ฐ ์์ฑํ ์ ๋ต
MySQL, PostgreSQL, SQLite
with a as (select *,case when customer_id%10=0 then 'A' else 'B' end bucket
from transactions),
b as (select customer_id, count(transaction_id) tr, sum(total_price) pr, bucket
from a
where not is_returned
group by customer_id, bucket)
select bucket,
count(distinct customer_id) user_count,
round(avg(tr),2) avg_orders,
round(avg(pr),2) avg_revenue
from b
group by bucket;Share article