我在尝试创建触发器时遇到语法错误。我远离MySQL专家,但设法根据我在stackoverflow上找到的信息创建以下代码。触发器的目的是检查销售行是否与拍卖项目(而不是立即购买项目)相关,如果是,则计算销售价格的10%溢价(将溢价金额插入高级列) 。 “listing_id”是列表和销售清单表之间的链接。
DELIMITER $$
CREATE TRIGGER add_premium
AFTER INSERT
ON sales_listings FOR EACH ROW
BEGIN
SET @listing_type := (SELECT listing_type
FROM listings
WHERE listings.listing_id = NEW.listing_id);
IF @listing_type = 'auction' THEN
NEW.premium = NEW.price * 0.1;
ELSE
NEW.premium = 0;
END IF;
END$$
DELIMITER;
这是语法错误:
#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 '.premium = NEW.price * 0.1;
ELSE
NEW.premium = 0;
END IF;
' at line 9
我做错了什么?
答案 0 :(得分:1)
作业必须以SELECT subjects.name,subjects.hours,careers.description...(choose the columns you want) FROM subjects INNER JOIN careers ON subjects.careers_id=careers.id;
开头。
all_careers = mysql_query(get all the careers and corresponding career_id from the table);