有两个表的条​​件Mysql事件

时间:2012-04-01 12:42:12

标签: mysql events

CREATE EVENT myevent4
ON SCHEDULE EVERY '1' MINUTE
DO
UPDATE receipt r
inner join loan l
on l.l_app_file_id=r.r_app_file_id
SET delinquent = (
    if r.receipt_on='Principal' AND r.receipt amount >= l.app_principal
    THEN 1
    ELSE 0

    END
);

我有两个表贷款和收据,我正在尝试创建一个事件,以便当列receipt_on(来自收据表)是' Principal'和column receipt_amount(来自收据表)大于或等于列app_principal(来自贷款表),然后将列deinquent(从收据表)设置为0,否则为1。 但是我的活动似乎有错误

1 个答案:

答案 0 :(得分:1)

尝试以下

CREATE EVENT myevent4
ON SCHEDULE EVERY '1' MINUTE
DO
UPDATE receipt r
inner join loan l
on l.l_app_file_id=r.r_app_file_id
SET delinquent = (
    case when r.receipt_on='Principal' AND r.receipt amount >= l.app_principal
    THEN 1
    ELSE 0

    END
)