我在PHPMyAdmin工作,我正在尝试添加触发器。由于语法错误(在触发器代码下面列出),我无法使触发器工作。
delimiter $$
CREATE TRIGGER new_sub
AFTER INSERT ON subscriptions
FOR EACH ROW
BEGIN
IF NEW.cancelled = 0 THEN
IF NEW.plan = 'pro' THEN
UPDATE statistics
SET statistics.premier_today = statistics.premier_today +1,
statistics.premier_this_week = statistics.premier_this_week+1,
statistics.premier_this_month = statistics.premier_this_month+1,
statistics.premier_all_time = statistics.premier_all_time+1,
statistics.revenue_today = statistics.revenue_today + 8,
statistics.revenue_this_week = statistics.revenue_this_week +8,
statistics.revenue_this_month = statistics.revenue_this_month +8;
END IF;
IF NEW.plan = 'single-event' THEN
UPDATE statistics
SET statistics.single_event_today = statistics.single_event_today +1,
statistics.single_even_this_week = statistics.single_event_this_week +1,
statistics.single_event_this_month = statistics.single_event_this_month +1,
statistics.single_event_all_time = statistics.single_event_all_time +1,
statistics.revenue_today = statistics.revenue_today + 25,
statistics.revenue_this_week = statistics.revenue_this_week +25,
statistics.revenue_this_month = statistics.revenue_this_month +25,
statistics.revenue_all_time = statistics.revenue_all_time +25;
END IF;
END IF;
END;$$
答案 0 :(得分:0)
case
用于选择。您可以在触发器中使用if
。这是你在找什么?
BEGIN
IF NEW.cancelled = 0 THEN
IF NEW.plan = 'pro' THEN
UPDATE statistics
SET statistics.premier_today = statistics.premier_today +1,
statistics.premier_this_week = statistics.premier_this_week+1,
statistics.premier_this_month = statistics.premier_this_month+1,
statistics.premier_all_time = statistics.premier_all_time+1,
statistics.revenue_today = statistics.revenue_today + 8,
statistics.revenue_this_week = statistics.revenue_this_week +8,
statistics.revenue_this_month = statistics.revenue_this_month +8;
END IF;
IF NEW.plan = 'single-event' THEN
UPDATE statistics
SET statistics.single_event_today = statistics.single_event_today +1,
statistics.single_even_this_week = statistics.single_event_this_week +1,
statistics.single_event_this_month = statistics.single_event_this_month +1,
statistics.single_event_all_time = statistics.single_event_all_time +1,
statistics.revenue_today = statistics.revenue_today + 25,
statistics.revenue_this_week = statistics.revenue_this_week +25,
statistics.revenue_this_month = statistics.revenue_this_month +25,
statistics.revenue_all_time = statistics.revenue_all_time +25;
END IF;
END IF;
END