在oracle中查找max

k5ifujac  于 2021-08-01  发布在  Java
关注(0)|答案(2)|浏览(415)

我希望在下面的示例中应用oraclesql中的max函数。

CN     10
EX     10
FW     10
CN     11
EX     11
FW     11

我希望结果如下。

CN     11
EX     11
FW     11

谢谢你的帮助。谢谢

4bbkushb

4bbkushb1#

获取max的方法有多种,如下所示: MAX 聚合函数:

select col1, max(col2) as max_col2
  from your_table
group by col1

使用 analytical function :

select * from
(select t.*, 
        row_number() over (partition by col1 order by col2 desc nulls last) as rn
  from your_table)
where rn = 1

使用 NOT EXISTS ```
select t.*
from your_table t
where not exists
(select 1 from your_table tt
where tt.col1 = t.col1
and tt.col2 > t.col2)

vptzau2j

vptzau2j2#

使用 max()group by ```
select col1,max(col2)
from tablename
group by col1

相关问题