Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
karthick.amace
Starting Member
23 Posts |
Posted - 2010-08-11 : 22:17:10
|
Hi bros, I need to compare the next row with the previous row of same table and produce nonidentical column.for eg... saymytable hasRow 1 => karthick 120 150 180Row 2 => karthick 150 150 180it want to gve output 150 of second row.Plz suggest me...- Karthick------------------------------------------------------"Desire makes what you wants to do" |
|
Sachin.Nand
2937 Posts |
Posted - 2010-08-12 : 00:12:46
|
Do you have any identical column?Just post more sample data as it would be more clear on what you exactly want.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-12 : 11:27:16
|
sounds likeSELECT other columns except rnFROM(SELECT ROW_NUMBER() OVER(PARTITION BY Name ORDER BY Field1 DESC) AS rn,*FROM Table)tWHERE rn=1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2010-08-12 : 11:44:13
|
quote: Originally posted by karthick.amace Hi bros, I need to compare the next row with the previous row of same table and produce nonidentical column.for eg... saymytable hasRow 1 => karthick 120 150 180Row 2 => karthick 150 150 180it want to gve output 150 of second row.Plz suggest me...
Is there a reason you couldn't just use a self join? Then you can compare rows to see which one meets your criteria (max value I guess since 150 is what you want in your example).SELECT DISTINCT Column1, Column2 FROM MyTable A, MyTable B WHERE A.id = B.id A.Value > b.Value Something like that? I don't understand what 'produce non-identical column' means but you can define that in the SELECT.r&r |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-12 : 12:28:05
|
quote: Originally posted by revdnrdy
quote: Originally posted by karthick.amace Hi bros, I need to compare the next row with the previous row of same table and produce nonidentical column.for eg... saymytable hasRow 1 => karthick 120 150 180Row 2 => karthick 150 150 180it want to gve output 150 of second row.Plz suggest me...
Is there a reason you couldn't just use a self join? Then you can compare rows to see which one meets your criteria (max value I guess since 150 is what you want in your example).SELECT DISTINCT Column1, Column2 FROM MyTable A, MyTable B WHERE A.id = B.id A.Value > b.Value Something like that? I don't understand what 'produce non-identical column' means but you can define that in the SELECT.r&r
seehttp://www.sqlservercentral.com/articles/T-SQL/61539/------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|