所以基本上我试图创建一个触发器,通过添加俯卧撑、引体向上和 3 英里跑步的分数来更新我的 300challenge 表中的分数。3英里跑的分数在下面的大SELECT
图中。
create trigger update_wscore
AFTER INSERT
ON 300challenge FOR EACH ROW
Create table temp(3mile_score integer);
insert into temp(3mile_score)
select
case
WHEN TIMEDIFF (3mile , '00:18:00') > '00:00:10'
THEN
CASE
WHEN
100 - (EXTRACT(MINUTE FROM TIMEDIFF (3mile, '00:18:00')) * 6 +
FLOOR(EXTRACT(SECOND FROM TIMEDIFF (3mile, '00:18:00')) / 10)) < 0
THEN 0
ELSE
100 - (EXTRACT(MINUTE FROM TIMEDIFF (3mile, '00:18:00')) * 6 +
FLOOR(EXTRACT(SECOND FROM TIMEDIFF (3mile, '00:18:00')) / 10))
END
ELSE 100
END
FROM 300challenge
WHERE wscore IS NULL;
UPDATE 300challenge
SET wscore = pushups * 2 + pullups * 5 + (select * from temp);
drop table temp;
我试过SELECT
直接在UPDATE wscore
语句中使用替换 theselect * fom temp
但它没有工作说我不能在语句内的子句中使用300challenge
表。SELECT FROM
UPDATE
之后,我尝试了上面当前显示的内容,创建了一个临时表,我在其中转储分数,他们读取它以便在UPDATE
.
但显然这种方法不足以欺骗系统,因为它现在会抛出一个错误,上面写着Explicit or implicit commit is not allowed in stored function or trigger.
我的想法有点用完了,所以如果有人可以提出一些建议,他们将非常受欢迎。
更新:
我现在也尝试CREATE TABLE TEMP
从触发器中删除,在触发器之外创建表(一次)并用drop table temp
a替换触发器的最后一行truncate table temp
,但显然我的网络主机不允许触发器为
TRIGGER command denied to user '--'@'localhost' for table '300challenge'
我的代码现在是这个
CREATE TABLE TEMP (3mile_score INT);
CREATE TRIGGER update_wscore
AFTER INSERT ON 300 challenge
FOR EACH ROW
INSERT INTO TEMP (3mile_score)
SELECT CASE
WHEN TIMEDIFF(3mile, '00:18:00') > '00:00:10'
THEN CASE
WHEN 100 - (EXTRACT(MINUTE FROM TIMEDIFF(3mile, '00:18:00')) * 6 +
FLOOR(EXTRACT(SECOND FROM TIMEDIFF(3mile, '00:18:00')) / 10)) < 0
THEN 0
ELSE 100 - (EXTRACT(MINUTE FROM TIMEDIFF(3mile, '00:18:00')) * 6 +
FLOOR(EXTRACT(SECOND FROM TIMEDIFF(3mile, '00:18:00')) / 10))
END
ELSE 100
END
FROM 300 challenge
WHERE wscore IS NULL;
UPDATE 300 challenge
SET wscore = pushups * 2 + pullups * 5 + (
SELECT *
FROM TEMP
);
TRUNCATE TABLE TEMP;