Thursday, 10 March 2011

Displaying current row and next row

SELECT    Hire_date,
                  Batch_id,
                  Status     Current_Status,
                  LEAD(Status)  Over(order by Hire_date) Previous_Status
FROM      HBC
WHERE    Batch_id=4; 

Output:

Hire_date               Batch_id            Current_Status  Previous_Status
07-Mar-2011          4                         2                            3
08-Mar-2011          4                         3                            4
09-Mar-2011          4                         4                           


No comments:

Post a Comment