![](/img/trans.png)
[英]How to compare rows in a table and keep the highest values in the row in Oracle
[英]How to select the rows with highest values in sequence in ORACLE
假設我有一個包含以下數據的表:
id | Value
_ _ _ _ _ _ _
1 0
2 1
3 2
4 0
5 1
6 0
7 1
8 2
9 3
10 4
我想只選擇那些達到最大值的行,按id排序。 結果行將是:
3 2
5 1
10 4
有任何想法嗎?
聽起來你想要做類似的事情
SELECT id,
value
FROM (SELECT id,
value,
lead(value) over (order by id) next_value
FROM your_table)
WHERE next_value < value
OR next_value IS NULL
select id, value
from (
select id, value, lead(value, 1, 0)over(order by id) as next from table
)
where next = 0
order by id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.