Sunday, 15 June 2014

sql - Remove duplicates from col1 when condition in col2 is met -


SQL Server 2008 R2 (SP2) 10.50.4263

I have a number in call 1 and one The indicator is (0 or 1) for first time buyers (FTB) can have one or two applicants in each application. For application with two applicants, I get two entries for the application:

  application ftb ----------- --- 1234 0 12345 0 12345 1 2345 1 23456 0 23456 0   

The desired result is each unique application and FTB. If an app has multiple FTB values ​​... take the highest (its always 0 or 1).

I want to see:

  application ftb - --------- --- 1234 0 12345 1 2345 1 23456 0  < / Pre> 

I am trying to use partitions ... but no luck table has been provided to me and I am unable to change it. It should be done in SQL and not the best. I have tried one million permutations and even myself find it in solution.

  Select Application, Mac (FTB) AS FTB, by application by yourTableBel Group   

I understand your question as you want to present only the rows in the table in your desired output and want to remove others, right? The easiest way to achieve this is to use a floating table.

  Select the application, MAX (ftb) via #yourTempTable from your table application in AS FTB;   

Delete all other rows ever since Remove from

  where to apply to your location (select the transfer application from #yourTempTable)   

and finally insert it from the temporary table back into your table.

  enter yourtel application (application, ftb) Select application, ftb to #yourTempTable;   

And so is it.

No comments:

Post a Comment