Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Compare rows in tables Expand / Collapse
Author
Message
Posted Monday, November 09, 2009 8:56 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 2:40 PM
Points: 25, Visits: 337
Hi,

I need to compare concecutive records in a single table and find the difference of 1 column .

Iam grouping with rownumber ,but how do I compare the row 2 with row 1
row3 with row2 and get the difference.


Thanks for your help.

Demin

Post #815847
Posted Monday, November 09, 2009 9:34 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 10, 2014 1:58 AM
Points: 1,240, Visits: 962
Hi,
if you have the row number for the table already you could join this table in on itself as below allow you to join one row to the next

SELECT	table1.column1,
table2.column2
FROM Sampletable as table 1
LEFT OUTER JOIN Sampletable as table2
ON table1.rownumber+1 = table2.rownumber

Post #815897
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse