第一时间想到
sql:
select *from t_test group by name, type order by score desc;
结果:
select *, max(score) as max_score from t_test group by name, type;
结果:
select a.* from t_test as a right join
(select name, type, max(score) as max_score from t_test group by name, type) as b on a.name = b.name and a.type = b.type and a.score = b.max_score
order by b.name, b.type;
结果:
二、 总结 通过max(), min()可以实现先排序后分组的功能; 用right join 可以获取全量信息; group by中的字段, select才能用, 如name, type; 同理可以实现:最小分数的同学信息和除了最高分外其它的信息(差集), 欢迎交流学习。 ———————————————— 版权声明:本文为CSDN博主「Bob丶抱抱」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/bob_baobao/article/details/78066113
评论