过滤器最大值 rn

Posted

技术标签:

【中文标题】过滤器最大值 rn【英文标题】:Filter max of rn 【发布时间】:2011-03-15 09:08:13 【问题描述】:

如何在此处过滤 rn 的最大值

select  *
from    (
        select  *
        ,       row_number() over (partition by name order by ox asc) as rn
        from    YourTable
        ) as SubQueryAlias
where   rn = 1

在其归档上方rn = 1

我要过滤rn = max(rn)

【问题讨论】:

【参考方案1】:

order by ox asc 更改为order by ox desc 并使用rn = 1

select  *
from    (
        select  *
        ,       row_number() over (partition by name order by ox desc) as rn
        from    YourTable
        ) as SubQueryAlias
where   rn = 1

【讨论】:

【参考方案2】:

检查这个以获得 rn = max(rn):

select top 1 * from 
( select * , 
    row_number() over (partition by name order by ox asc) 
    as rn from YourTable ) 
as SubQueryAlias 
order by rn desc

【讨论】:

以上是关于过滤器最大值 rn的主要内容,如果未能解决你的问题,请参考以下文章

Linux 查看占用资源cpu内存最大的进程命令

Oracle分组最大值数据

使用过滤器获取分区数据的最小值和最大值

根据最大值过滤 SQL Server 数据

按字段最大值过滤重复项

Oracle分组后取某列最大值的行数据