sql - Decompose one row into multi rows according conditions -
i have table :
id a_kode b_kode c_kode -------------------------------- 1 10 12 0 2 15 0 0 3 0 16 17 4 0 0 0
require query provide result :
id kode ------------ 1 10 1 12 2 15 3 16 3 17 4 0
first need union rows exists not 0 value , add rows 0 columns values zeroes.
select id,a_kode kode t a_kode<>0 union select id,b_kode kode t b_kode<>0 union select id,c_kode kode t c_kode<>0 union select id,0 kode t a_kode=0 , b_kode=0 , c_kode=0
Comments
Post a Comment