compare current row value with next row value
ID
------
1
1
2
2
3
4
5
5
5
6
7
7
7
8
9
9
10
9
I need to compare first row value with next row value. If they are equal display y in another column.
ID flag
------ -------
1 y
1 n
2 y
2 开发者_Go百科n
3 n
4
5
5
5
6
7
7
7
8
9
9
10
9
I would like this query to run in Oracle.
You can use analytic functions (window functions):
select id,
case
when lead(id, 1, 0) over (order by id) = id then 'Y'
else 'N'
end
from your_ids_table;
You can replace order by
clause with anything you need.
精彩评论