一、用户行为分析
1、被收藏次数最多的商品为?-so easy
select mch_id,count(1)
from xhs_fav_rcd
group by mch_id
想得到商品名称, 就再连接一下表一
2、购买人数最多的商品类目为? -平平无奇
select a.gd_typ,count(distinct c.cust_uid) as cnt
from xhs_pchs_rcd c left join gd_inf a
on a.gd_id=c.mch_id
group by a.gd_typ
order by 2 desc
3、被收藏,却未被购买的商品?-轻松拿下
select distinct mch_id
from xhs_fav_rcd b
where mch_id not in
(select distinct mch_id from xhs_pchs_rcd)
4、哪个商品,既被同一个用户购买,又被同一个用户收藏,且购买人数最多?–不难
用内连接进行筛选
select b.mch_id,count(1)
fr