ALTER VIEW v_persentase_kerusakan_gedung AS
SELECT 
    vkg.id,
    k_1/t_1_2 * 100 as p_1,
    k_1/t_1_2 * sk1.standar as pt_1,
    k_2/t_1_2 * 100 as p_2,
    k_2/t_1_2 * sk2.standar as pt_2,
    k_3/t_3_4_18 * 100 as p_3,
    k_3/t_3_4_18 * sk3.standar as pt_3,
    k_4/t_3_4_18 * 100 as p_4,
    k_4/t_3_4_18 * sk4.standar as pt_4,
    k_5/t_5_9_17 * 100 as p_5,
    k_5/t_5_9_17 * sk5.standar as pt_5,
    k_6/t_6_7_8_20 * 100 as p_6,
    k_6/t_6_7_8_20 * sk6.standar as pt_6,
    k_7/t_6_7_8_20 * 100 as p_7,
    k_7/t_6_7_8_20 * sk7.standar as pt_7,
    k_8/t_6_7_8_20 * 100 as p_8,
    k_8/t_6_7_8_20 * sk8.standar as pt_8,
    k_9/t_5_9_17 * 100 as p_9,
    k_9/t_5_9_17 * sk9.standar as pt_9,
    k_10/(t_10_11_19___1 + t_10_11_19___2) * 100 as p_10,
    k_10/(t_10_11_19___1 + t_10_11_19___2) * sk10.standar as pt_10,
    k_11/(t_10_11_19___1 + t_10_11_19___2) * 100 as p_11,
    k_11/(t_10_11_19___1 + t_10_11_19___2) * sk11.standar as pt_11,
    k_12/t_12 * 100 as p_12,
    k_12/t_12 * sk12.standar as pt_12,
    k_13/t_13 * 100 as p_13,
    k_13/t_13 * sk13.standar as pt_13,
    k_14/t_14 * 100 as p_14,
    k_14/t_14 * sk14.standar as pt_14,
    k_15/t_15 * 100 as p_15,
    k_15/t_15 * sk15.standar as pt_15,
    k_16/t_16 * 100 as p_16,
    k_16/t_16 * sk16.standar as pt_16,
    k_17/t_5_9_17 * 100 as p_17,
    k_17/t_5_9_17 * sk17.standar as pt_17,
    k_18/t_3_4_18 * 100 as p_18,
    k_18/t_3_4_18 * sk18.standar as pt_18,
    k_19/(t_10_11_19___1 + t_10_11_19___2) * 100 as p_19,
    k_19/(t_10_11_19___1 + t_10_11_19___2) * sk19.standar as pt_19,
    k_20/t_6_7_8_20 * 100 as p_20,
    k_20/t_6_7_8_20 * sk20.standar as pt_20
FROM v_kerusakan_gedung vkg
LEFT JOIN sub_komponen sk1 ON sk1.id = 1
LEFT JOIN sub_komponen sk2 ON sk2.id = 2
LEFT JOIN sub_komponen sk3 ON sk3.id = 3
LEFT JOIN sub_komponen sk4 ON sk4.id = 4
LEFT JOIN sub_komponen sk5 ON sk5.id = 5
LEFT JOIN sub_komponen sk6 ON sk6.id = 6
LEFT JOIN sub_komponen sk7 ON sk7.id = 7
LEFT JOIN sub_komponen sk8 ON sk8.id = 8
LEFT JOIN sub_komponen sk9 ON sk9.id = 9
LEFT JOIN sub_komponen sk10 ON sk10.id = 10
LEFT JOIN sub_komponen sk11 ON sk11.id = 11
LEFT JOIN sub_komponen sk12 ON sk12.id = 12
LEFT JOIN sub_komponen sk13 ON sk13.id = 13
LEFT JOIN sub_komponen sk14 ON sk14.id = 14
LEFT JOIN sub_komponen sk15 ON sk15.id = 15
LEFT JOIN sub_komponen sk16 ON sk16.id = 16
LEFT JOIN sub_komponen sk17 ON sk17.id = 17
LEFT JOIN sub_komponen sk18 ON sk18.id = 18
LEFT JOIN sub_komponen sk19 ON sk19.id = 19
LEFT JOIN sub_komponen sk20 ON sk20.id = 20;
