Home > database >  Refer to the MySQL statement automatically update sum to another table data
Refer to the MySQL statement automatically update sum to another table data

Time:09-24

Is this table A


Is this table B



I want to put the table B field xiaofei summation. The filter is user and dianhua
After get the sum of values, automatic updates to the table A filter user and dianhua to z_xiaofei field.

As long as there is update, or delete data. Table B is automated

CodePudding user response:

 
The update kh_list kl, (select sum (xiaofei) z_xiaofei, ` user `, dianhua from kh_yc GROUP BY ` user `, dianhua) ky
The set kl. Z_xiaofei=ky. Z_xiaofei
Where kl. ` user `=ky. ` user ` and kl. Dianhua=ky. Dianhua

CodePudding user response:

Write a trigger

CodePudding user response:

Excuse me maple VS mark eldest brother, if this in navicat, should be to create a new event? Or function?
  • Related