您的位置:首页 > 数据库

接上(SQL中遇到多条相同内容只取一条的最简单实现)多字段情况

2012-11-07 17:20 309 查看
上面的例子中是只有一个字段不相同,假如有两个字段出现相同呢?要求查处第三个字段的最大值该如何做呢?

其实很简单,在原先的基础上稍微做下修改即可:

原先的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类型
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐