数据库
首页 > 数据库> > SQL18、分组计算练习题

SQL18、分组计算练习题

作者:互联网

思路:使用GROUP BY关键字对数据进行分组,即不含有重复的数据,用来统计数据

代码解释:对数据进行分组,注意这里性别和学校都有可能重复,所以都要进行分组。然后从表user_profile中取出列genderuniversity以及一些计算数据

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

题目:https://www.nowcoder.com/practice/009d8067d2df47fea429afe2e7b9de45?tpId=199&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D199

标签:练习题,GROUP,gender,university,分组,user,SQL18,avg
来源: https://www.cnblogs.com/tiansz/p/16465224.html