当某个记录值包含在来自其他表的新插入记录中时,mysql触发器更新记录

时间:2015-06-29 09:01:27

标签: mysql sql triggers nested gammu

我是新来的,真的需要帮助。解决它几天没有遇到解决方案。我和gammu一起工作。

我有这些表

表格收件箱

+--------------+
| TextDecoded  |
+--------------+
|xx200.001,00xx|
|xx300.001,00xx|
+--------------+

表格余额

+-------------+----------------+----------------+------------+
| costumer_id | refill_balance | refill_nominal | status     |
+-------------+----------------+----------------+------------+
|          1  | 2000001        | 300.001,00     |    verified|
|          1  | 2000001        | 200.001,00     |not_verified|
+-------------+----------------+----------------+------------+

表costumer

+-------------+----------------+----------------+
| costumer_id | name           | balance        |
+-------------+----------------+----------------+
|          1  | bond           | 3000001        |
+-------------+----------------+----------------+

场景是:

  1. 当有传入消息时,它将保存在inbox.TextDecoded
  2. 将检查新传入的消息是否包含balance.refill_nominal或不包含
  3. 如果no.2为真,则将验证balance.status
  4. 如果没有完成,那么costumer.balance的值将添加balance.refill_balance的值
  5. 我已尝试使用此触发器进行balance.status更新

    DELIMITER $$
    CREATE TRIGGER verify_refill AFTER INSERT ON inbox
    FOR EACH ROW BEGIN
    UPDATE balance
    SET status='verified'
    WHERE refill_nominal=(SELECT balance.refill_nominal FROM balance JOIN inbox ON NEW.inbox.TextDecoded LIKE CONCAT('%',balance.refill_nominal,'%') AND balance.status='not_verified';
    END $$
    

    尝试使用此触发器添加costumer.balance

    DELIMITER
    CREATE TRIGGER add_balance AFTER UPDATE ON balance
    FOR EACH ROW BEGIN
    UPDATE costumer
    SET balance=OLD.balance+NEW.refill_balance
    WHERE
    costumer_id=NEW.costumer_id
    END $$
    

    它们都不起作用。请帮帮我..

0 个答案:

没有答案