select
# 这里用distinct 排除重复device_id情况
count(distinct device_id) as male_num,
avg(gpa) as avg_gpa
from user_profile
group by gender
having gender='male'
这里说下两种解法吧
-
select count(gender) as male_num, round(avg(gpa), 1) as avg_gpa from user_profile where gender="male";
一般是建议直接用group by 然后 having, 这样的效率会略高



京公网安备 11010502036488号