面试题:

统计各个渠道的人数占比:
在这里插入图片描述

sql实现:

select 
	channel, 
	g_cnt/cnt
from(select *
	 from(select channel, count(distinct uid) g_cnt from user_profile group by channel)t1
	 join (select count(*)cnt from user_profile)t2 on 1=1
	)tt

查询结果:
在这里插入图片描述

Logo

更多推荐