现在运营想要对每个学校不同性别的用户活跃情况和发帖数量进行分析,请分别计算出每个学校每种性别的用户数、30天内平均活跃天数和平均发帖数量。
用户信息表:user_profile,30天内活跃天数字段(active_days_within_30),发帖数量字段(question_cnt),回答数量字段(answer_cnt)
select
gender,university, count(id),
round(avg(active_days_within_30), 1) as avg_active_day,
round(avg(question_cnt), 1) as question_cnt
from
user_profile
group by
university,gender;
分组依据 学校和性别,round(_,1)四舍五入保留一位小数 。
统计每个学校各难度的用户平均刷题数
运营想要计算一些参加了答题的不同学校、不同难度的用户平均答题量
select
university,
difficult_level,
round(
count(question_practice_detail.question_id) / count(distinct question_practice_detail.device_id), 4)
as avg_answer_cnt
from
user_profile,
question_detail,
question_practice_detail
where
user_profile.device_id = question_practice_detail.device_id
and question_practice_detail.question_id = question_detail.question_id
group by
university, difficult_level;
现在运营想要分别查看学校为山东大学或者性别为男性的用户的device_id、gender、age和gpa数据,请取出相应结果,结果不去重。
select
device_id, gender, age, gpa
from
user_profile
where
university = '山东大学'
union all
select
device_id, gender, age, gpa
from
user_profile
where
gender = 'male';
union 联合结果没有重复值, union all 联合结果有重复值。