简体   繁体   中英

MySQL update field from other table with grouped

Here is my select query :

SELECT
    sap.stat_ap_id, ju.mu, SUM(ju.ju_amount_p) total_amount_p, SUM(ju.ju_amount) konversi_idr
FROM 
    t_stat_ap sap
    LEFT JOIN t_ju ju ON sap.ju_session_id_ap = ju.ju_session_id AND ju.post_type = 't_statement' AND ju.ju_stat > '0'
    LEFT JOIN t_acc_level3 as v3 ON v3.level3_id = ju.ju_akun
    LEFT JOIN t_acc_level2 as v2 ON v2.level2_id = v3.level2_id
    LEFT JOIN t_acc_level1 as v1 ON v1.level1_id = v2.level1_id
WHERE 1
    AND ju.ju_stat > '0'
    AND v1.level1_id = '2'
GROUP BY sap.stat_ap_id, ju.mu

Is that possible to update each row t_stat_ap table ???

Yes, you can put you update query in foreach loop up to the number of rows present there in the table. The query you have written is only selecting(filtering) data from those tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM