Oracle 中有如下行
ID value
1 1
1 2
2 1
2 2
2 3
用什么样的 SQL 能得到
ID value
1 2
2 3
------解决方案--------------------
with t as
(select 1 id, 1 value
from dual
union all
select 1 id, 2 value
from dual
union all
select 2 id, 1 value
from dual
union all
select 2 id, 3 value
from dual
union all
select 2 id, 2 value from dual)
select t1.id, t1.value
from (select t.*,
row_number() over(partition by id order by value desc) rn
from t) t1
where t1.rn = 1;
------解决方案--------------------
SELECT id,max(VALUE)
FROM 表名
GROUP BY id;