【问题标题】:MySQL Trigger Syntax Error union two/three tablesMySQL 触发器语法错误联合二/三表
【发布时间】:2012-11-30 10:26:48
【问题描述】:

我写了以下代码:

create trigger money after update on `things`
for each row
begin
   Select @c1=sum(`thing_cost`) from `things`
   UNION
   Select @c2=sum(`salary`) from `dude_base`
   Update `current` set `curr_cash`=@c1*@c2/100
end;
$$

表“东西”有:

id1 (PK)
name
thing_cost

表 dude_base 有:

id2 (PK)
salary
name, etc. irrevelant

表当前有:

id1 (FK)
id2(FK)
curr_cash

我收到以下错误:

 #1064 - You have an error in your SQL syntax; check the manual that corresponds to   
 your MySQL server version for the right syntax to use
 near 'Update `current` set `curr_cash`=@c1*@c2/100; END' at line 7

有什么帮助吗?

【问题讨论】:

    标签: mysql sql triggers


    【解决方案1】:

    我认为你应该有一个分号 ; 喜欢

    Select @c2=sum(`salary`) from `dude_base`;
    

    结束此查询,因为UPDATE 是另一个查询

    // 编辑

    这样试试

    SET @c1 = (SELECT sum(`thing_cost`) from `things`);
    SET @c2 = (SELECT sum(`salary`) from `dude_base`);
    UPDATE `current` SET `curr_cash` = @c1 * @c2 / 100
    

    【讨论】:

    • 这有所帮助,但现在又遇到了另一个问题:#1415 - Not allowed to return a result set from a trigger
    • 我很高兴它成功了 :) 但如果它有效,你应该将我的帖子设置为答案 :)
    • 你可以点击我答案左边的“打勾”图标 - ✓ 像这样:)
    猜你喜欢
    • 2015-08-09
    • 1970-01-01
    • 2015-06-02
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-21
    相关资源
    最近更新 更多