group records according to column hi how can make this result query:



to this:



I have this code and i know it's still farfetched:

select
        max(case subcod when 'DISABILITY' then A end) as disability,
        max(case subcod when 'DISMEMBERMENT' then B end) as dismemberment,
        max(case subcod when 'MEDICAL' then C end) as medical,
        max(case subcod when 'OTHERS' then D end) as others
    from
        (
        select subcod, description as A, null as B, null as C, null as D from grp_appl_ref where ref_id = 'RIDERS' and subcod = 'DISABILITY'
        union
        select subcod, null, description, null, null from grp_appl_ref where ref_id = 'RIDERS' and subcod = 'DISMEMBERMENT'
        union
        select subcod, null, null, description, null from grp_appl_ref where ref_id = 'RIDERS' and subcod = 'MEDICAL'
        union
        select subcod, null, null, null, description from grp_appl_ref where ref_id = 'RIDERS' and subcod = 'OTHERS'
        )


I was wondering if there's another reserved word instead of max so i can remove the null values so the cells with values would move up.

is it possible?

thanks,
Use CASE statement as following

SELECT  
CASE WHEN ref_id = 'RIDERS' and subcod = 'DISABILITY' THEN   description ELSE NULL END AS DISABILITY,
CASE WHEN ref_id = 'RIDERS' and subcod = 'DISMEMBERMENT' THEN   description ELSE NULL END AS DISMEMBERMENT,
CASE WHEN ref_id = 'RIDERS' and subcod = 'MEDICAL' THEN   description ELSE NULL END AS MEDICAL,
CASE WHEN ref_id = 'RIDERS' and subcod = 'OTHERS' THEN   description ELSE NULL END AS OTHERS
FROM grp_appl_ref


If at any stage need to sort out records while putting NULL values at the end use CASE statement in ORDER BY clause

ORDER BY CASE columnName WHEN NULL THEN 1 ELSE 0 END