Home » SQL & PL/SQL » SQL & PL/SQL » compare column value to a column value in next row (Oracle Database 11g Enterprise Edition Release 11.1.0.7.0)
compare column value to a column value in next row [message #641764] Fri, 21 August 2015 15:37 Go to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
Hello all,

I want to compare 2 values of same column in same row - like
Quote:

ROW COLUMN COMP_VAL
1 A 0
2 B A
3 C B
4 D C
5 E D


How to get the values in the COMP_VAL columns, in a single SELECT statment, without using LOOP. I've tried rownum, but it doesnt work.

thanks,
rk
Re: compare column value to a column value in next row [message #641765 is a reply to message #641764] Fri, 21 August 2015 16:51 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3269
Registered: January 2010
Location: Connecticut, USA
Senior Member
Use analytic function LAG.

SY.
Re: compare column value to a column value in next row [message #641802 is a reply to message #641765] Mon, 24 August 2015 08:53 Go to previous message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
Thanks. I was using the sql in the oracle reports. It seems to be working.
Previous Topic: Oracle Hierarchical Query max_level/connect_by_is_root
Next Topic: Table partition
Goto Forum:
  


Current Time: Fri Mar 29 01:11:47 CDT 2024