如何执行实现此条件的触发器?

How to do trigger that implements this condition?

我需要实现这个过程的触发器:

我应该在 table money 的 table paym 两列 table1table2 中为该用户添加一些数字 50 ] 不为空。

例如:用户 'John' 的两列都不为空,并且在 table money.

中添加了 50

下面 table 中的示例:

table: paym

 ID        username        table1        Table2  
+-------+-------------+-------------+-----------+
|   1   |  John       |  Value      |    Value  |
+-------+-------------+-------------+-----------+
|   2   |  Alex       |  Null       |    Null   |
+-------+-------------+-------------+-----------+

Table: money

 ID      username      total_money      
+-------+-------------+-------------+
|   1   |  John       |     50      | 
+-------+-------------+-------------+
|   2   |  Alex       |     0       |
+-------+-------------+-------------+

查询为此:(不确定是否正确)

UPDATE 
 money
SET 
 money.total_money = money.total_money + 50
INNER JOIN 
 paym
ON
 money.username = paym.username
WHERE
   (paym.Table1 IS NOT NULL OR paym.Table1 <> '')
 AND
   (paym.Table2 IS NOT NULL OR paym.Table2 <> '')

这是用于该目的的触发器:

DELIMITER $$
CREATE trigger update_money_after_paym
AFTER INSERT ON paym
FOR EACH ROW
BEGIN
    IF (NEW.table1 IS NOT NULL AND NEW.table2 IS NOT NULL) THEN
        UPDATE money SET total_money = total_money + 50 WHERE username = NEW.username;
    END IF;
END;
$$
DELIMITER;

每次插入 table paym 后,代码将 运行。如果新插入的记录的 table1table2 列都设置为非 NULL 值,则触发器 运行 是一个 UPDATE 查询,它将 50 添加到table money 中的列 total_moneypaym.

中新插入的记录具有相同 username 的记录