how to combine column in mysql

Viewed 25

How to combine this column if kode_discount and cust_disc_code have the same value,

I tried to use this method,

SELECT * 
FROM (
     SELECT pkb.kode_discount,
            pkb.cust_disc_code,
            IF (SUBSTRING(pkb.kode_discount,1,1)='E',dish.nama_discount,'') diskon_event,
            0 diskon_member 
     FROM pkbs pkb 
     JOIN discount_headers dish ON pkb.kode_discount=dish.kode_discount 
     WHERE pkb.kode_discount IS NOT NULL 
       AND pkb.kode_discount !='' 
       AND pkb.cust_disc_code IS NOT NULL 
       AND pkb.cust_disc_code !='' 
     GROUP BY kode_discount,pkb.cust_disc_code 
   UNION ALL
     SELECT pkb.kode_discount,
            pkb.cust_disc_code,
            0 diskon_event,
            IF (SUBSTRING(pkb.cust_disc_code,1,1)='C',dish.nama_discount,'') diskon_member 
     FROM pkbs pkb 
     JOIN discount_headers dish ON pkb.cust_disc_code=dish.kode_discount 
     WHERE pkb.kode_discount IS NOT NULL 
       AND pkb.kode_discount !='' 
       AND pkb.cust_disc_code IS NOT NULL 
       AND pkb.cust_disc_code !='' 
     GROUP BY kode_discount,pkb.cust_disc_code
    ) a

but failed, I tried group by which also failed.

this image

0 Answers
Related