Oracle的分组排序功能实现最大值一列数据获取

发布时间 2023-06-12 09:34:19作者: AlenYang

需求:按某列的最大值取整行数据。

 

       select <include refid="ALL_COLUMNS"/>
        from (
            select <include refid="ALL_COLUMNS"/>, ROW_NUMBER() OVER (ORDER BY TOKEN_RATE DESC) AS rn
            from <include refid="TABLE_NAME"/>
            where TOKEN_RATE is not null
            and ts >= #{time.from}
            and ts < #{time.to}
        ) t
        WHERE t.rn = 1