最近项目中经常遇到根据某个字段分组统计,所以总结一下,我遇到这种问题的思路
#用到临时表
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)
mysql 中根据某个字段分组统计 如何优化
最新推荐文章于 2024-09-02 20:00:00 发布
本文分享了在项目中遇到的SQL分组统计问题解决思路,包括使用临时表和索引优化的方法,通过具体代码示例展示了如何根据字段进行高效的数据统计。
2192

被折叠的 条评论
为什么被折叠?



