题解|20. 618不同价格区间的购买人数
618不同价格区间的购买人数
明确题意:
统计0-50,50-100,100-200三个价格区间的购买人数
问题拆解:
- 关联行为表于产品表的价格。知识点:join
- 筛选购买行为的记录。知识点:where
- 把价格变成区间。知识点:case when then
- 统计每个区间的购买人数。按区间分组group by;统计人数count(distinct cust_uid)
代码实现:
select
case
when price<=50 then "0-50"
when price<=100 then "50-100"
when price<=200 then "100-200"
end as price_cut,
count(distinct cust_uid) as price_cut_num
from tb_clk_rcd
join tb_prd_map using(prd_id)
where if_buy=1
group by price_cut