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
);

我有两个表loan和receipt,我正在尝试创建一个事件,以便当receipt_on(from receipt table)列是'Principal',receipt_amount(from receipt table)列大于或等于app_Principal(from loan table)列时,将column default(from receipt table)设置为0 else 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
)

关于mysql - 有两个表的条​​件MySQL事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9964458/

10-12 05:27