How to arrange data in sql server table -


i tried many query achieve expected result , couldn't find solution.

actual:-

id | empdailyfee | empmonthlyfee | compdailyfee | compmnthlyfee  1        null         12            null               null  1         50         null           null               null  1         60         null           null               null  2        50           null           null               null  3        null          30            null               null 

expected :-

id | empdailyfee | empmonthlyfee | compdailyfee | compmnthlyfee  1        50            12            null               null  1        60            12            null               null  2        50           null           null               null  3        null          30            null               null 

this looks table smell me since rows sharing same id value different empdailyfee/empmonthlyfee values. in particular case can expected output this:

select t1.id, t1.empdailyfee, t2.empmonthlyfee @test t1 inner join @test t2 on t1.id = t2.id t1.empdailyfee not null , t2.empmonthlyfee not null union select t1.id, t1.empdailyfee, t1.empmonthlyfee @test t1 (t1.empdailyfee not null or t1.empmonthlyfee not null) , t1.id not in (     select t3.id     @test t3         inner join @test t2 on t3.id = t2.id     t3.empdailyfee not null , t2.empmonthlyfee not null ) 

this has been tested on sql fiddle

note: reason why did not include compdailyfee , compmnthlyfee because values of both actual , expected results null. trying write "simple-as-possible" query based on op has provided.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -