INSERT INTO users (phone, no_of_coupon)
SELECT couponentries.phone, 1
FROM couponentries LEFT JOIN users ON couponentries.phone =
users.phone
WHERE users.phone IS NULL
ON DUPLICATE KEY UPDATE users.no_of_coupon = users.no_of_coupon + 1;
我正在尝试在优惠券表中输入日期,然后它会自动仅将电话号码插入到用户表中。如果有重复的电话号码,no_of_coupon将增加1.但是当我在phpmyadmin触发器trigger中执行此代码时,它在下面有一个错误。有人可以帮帮我吗?感谢
无法执行Column' users.no_of_coupon'在字段列表中是不明确的
答案 0 :(得分:0)
您需要为join子句
中使用的users表提供别名INSERT INTO users (phone, no_of_coupon)
SELECT c.phone, 1
FROM couponentries c
LEFT JOIN users u ON c.phone = u.phone
WHERE u.phone IS NULL
ON DUPLICATE KEY UPDATE users.no_of_coupon = users.no_of_coupon + 1;
我猜你不需要你可以使用的连接部分
INSERT INTO users (phone)
SELECT c.phone
FROM couponentries c
ON DUPLICATE KEY UPDATE no_of_coupon = no_of_coupon + 1;