Case expression with four columns, i.e. attributes
13:10 02 Jul 2019

I have a table with values "1", "0" or "". The table has four columns: p, q, r and s.

I need help creating a case expression that returns values when the attribute is equal to 1.

enter image description here

  • For ID 5 the case expression should return "p s".

  • For ID 14 the case expression should return "s".

  • For ID 33 the case expression should return 'p r s". And so on.

Do I need to come with a case expression that has every possible combination? Or is there a simpler way. Below is what I have come up with thus far.

case 
    when p = 1  and q =1 then "p q"
    when p = 1  and r =1 then "p r"
    when p = 1  and s =1 then "p s"
    when r = 1 then r 
    when q = 1 then q 
    when r = 1 then r 
    when s = 1 then s 
    else ''

 end
sql oracle-database