上面的例子中是只有一个字段不相同,假如有两个字段出现相同呢?要求查处第三个字段的最大值该如何做呢?
其实很简单,在原先的基础上稍微做下修改即可:
原先的SQL语句:
select * from timeand as a where not exists(select 1 from timeand where a.time = time and a.total<total);
可修改为:
select * from timeand as a where not exists(select 1 from timeand where a.time = time and (a.total<total or (a.total=total and a.outtotal<outtotal)));
其中outtotal是另外一个字段,为Int类型
本文介绍了一种在SQL查询中如何找出当多个字段部分相同时,如何选取第三个字段最大值的方法。通过调整原有的SQL语句,实现了在两字段相同的情况下获取第三个字段最大值的功能。
172万+

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



