I need to update a field calculated by the sum of multiple selects. The selection part is working, but I can't find a way to update the user table
user
+------+---------+
| id   | total   |
+------+---------+
| 1    |         | 
| 2    |         |
unita
+------+-------+-----+
| id   | uid   | num |
+------+-------+-----+
| 1    | 1     | 25  |
| 1    | 2     | 10  |
unitb
+------+-------+-----+
| id   | uid   | num |
+------+-------+-----+
| 9    | 1     | 225 |
| 9    | 2     | 10  |
class 
+------+--------+------+
| id   | name   | cost |
+------+--------+------+
| 1    | class1 | 100  |
| 9    | class9 | 500  |
SELECT uid, SUM(score) FROM (
    SELECT unita.uid, SUM(class.cost * unita.num) AS cost FROM unita, class WHERE unita.id = class.id GROUP BY unita.uid
    UNION
    SELECT unita.uid, SUM(class.cost * unitb.num) AS cost FROM unitb, class WHERE unitb.id = class.id GROUP BY unitb.uid
) x GROUP BY uid
The update command should sum all cost per user
User 1: (25*100)+(225*500) = 115000
User 2: (10*100)+(10*500) = 6000
It this possible within 1 SQL command. The unit tables are locked, so I can't modify anything
 
     
    