赞
踩
最近项目中经常遇到根据某个字段分组统计,所以总结一下,我遇到这种问题的思路
#用到临时表
select stu.name,sta.grade,count() from student as stu inner join statistics as sta USING(uid) where sta.grade>90 group by stu.uid
#用到索引
select stu.name,c.grade,c.num from student as stu inner join (select uid,
count() as num,grade from statistics where statistics.grade>90 group by uid ) as c USING(uid)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。