1、groupby用法:根据性别和学校来分组
select
gender,university,
count(gender)as user_num,
avg(active_days_within_30) as avg_active_day,
avg(question_cnt) as avg_question_cnt
from
user_profile
group by gender,university
2、groupby 结合having语法,进行分组过滤
select
university,avg(question_cnt) as avg_question_cnt,
avg(answer_cnt) as avganswer_cnt
from
user_profile
group by
university
having avg(question_cnt)<5 or avg(answer_cnt)<20
3、groupby结合orderby 分组排序(升序是asc,降序是desc)
select
university,avg(question_cnt) as avg_question_cnt
from
user_profile group by university
order by avg_question_cnt asc