sql - Amalgamating rows in a table and ommitting NULL values -


what script return table amalgamates rows id in following table , remove null values id appears more once. instance id 3 appears twice , and id 217 appears once , after script run below how script has old school compatible sql2000. thank you.

id  preoporg    preoptreatment      postoporg   postoptreatment 3   rba11           02              rba11       06 217 null            null            rn325       02 

and on

id      preoporg    preoptreatment      postoporg   postoptreatment 3       rba11           02              null        null 3       null            null            rba11       06 217     null            null            rn325       02 364     null            null            rba11       02 369     null            null            rn325       02 481     gr123           05              null        null 834     rba11           02              null        null 834     null            null            rba11       04 1066    null            null            rba11       05 2123    null            null            rba11       05 2246    null            null            rba11       02 2246    rba11           02              null        null 2512    rba11           04              null        null 2512    null            null            rba11       06 2694    null            null            rn325       05 2892    null            null            rba11       06 2892    rba11           05              null        null 3311    rba11           05              null        null 3311    null            null            rba11       06 3344    rba11           02              null        null 3362    rba11           02              null        null 3770    rba11           05              null        null 

you can aggregation:

select id, max(preoporg) preoporg, max(preoptreatment) preoptreatment,        max(postoporg) postoporg, max(postoptreatment) postoptreatment table t group id; 

this works data have provided, because 1 field populated. there no danger of "losing" information in 1 of columns, if true.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -