mysql中group by的数据顺序

本文共有331个字,关键词:

问题:如何让group by的数据按一定的顺序进行合并,而不是取id最小的数据
解决:group by 比order by先执行,order by不会对group by 内部进行排序
方法:
select uid, class_id, max(score) from scores where school=2 group by class_id order by score;
这样就可以取出学校id为2的所有班级中最高的分数了
注意:此处的uid必不是分数最高的学生id,而是score表中id最小的uid

注:http://blog.csdn.net/agileclipse/article/details/12775381

版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论