题解 | 计算男生人数以及平均GPA
select count(gender) as male_num ,round(avg(gpa),1) as avg_gpa from user_profile where gender="male" # round(value,n),其中value代表想要限制小数位数的字段,n代表想要限制的小数位数 # 错误答案: # select count(gender="male") as male_num ,round(avg(gpa),1) as avg_gpa # from user_profile # group by male_num # 原因分析: # 语句gender="male"是限制条件范围,应该用where写在后面,不应出现在select中 # group by使用场景:查询男女分别的平均gpa情况,即分成男、女2组看平均GPA