【场景】:每个学校不同性别的用户 【分类】:分组计算
分析思路
select 查询结果 [性别;学校;count(设备ID) as 用户数;avg(30天内活跃记录) as 平均活跃天数;avg(发帖记录) as 平均发帖数]
from 从哪张表中查找数据 [user_profile]
group by 分组 [学校;性别]
求解代码
方法一:
select
gender,
university,
count(device_id) as user_num,
avg(active_days_within_30) as avg_active_day,
avg(question_cnt) as avg_question_cnt
from user_profile
group by university, gender