Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Find rows with a change in a field compared with the previous row
SQL> SELECT SESSION_ID, DECODE(LIGHT_ON,'N','OFF','ON') STATUS 2 FROM ( SELECT SESSION_ID, LIGHT_ON, LAG(LIGHT_ON) OVER (ORDER BY SESSION_ID) AS PREV_LIGHT_ON FROM MY_TABLE )3 WHERE LIGHT_ON != PREV_LIGHT_ON
SESSION_ID STATUS
---------- ---
5 OFF 8 ON 14 OFF
SQL> Received on Mon Jun 06 2005 - 10:02:07 CDT