ERROR 1109(42S02):未知表格' T'在字段列表中

时间:2017-11-17 16:37:27

标签: mysql

 DELIMITER //         
DROP TRIGGER IF EXISTS temp;
CREATE TRIGGER `temp` 
AFTER UPDATE ON charges 
FOR EACH ROW
BEGIN
IF(OLD.end_time IS NULL)
THEN
SET @parking_hours = TIMESTAMPDIFF(HOUR, NEW.start_time , NEW.end_time);
SET @parking_minutes = TIMESTAMPDIFF(MINUTE, NEW.start_time , NEW.end_time);
CALL check_booking(NEW.userid);
IF(WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 0 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 1 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 2 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 3 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 4 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 5 AND NEW.start_time  >= DATE_FORMAT(NEW.start_time, '%k:%i:%s') AND NEW.start_time <=DATE_FORMAT(NEW.start_time, '%k:%i:%s'))
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, W.per_entry, W.first_hour, W.hourly, W.every_30min, W.minute, W.start_time, W.end_time
FROM weekday_rates_1 W
WHERE NEW.carparkid = W.carparkid;

ELSEIF(WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 6)
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, S.per_entry, S.first_hour, S.hourly, S.every_30min, S.minute, S.start_time, S.end_time
FROM saturday_rates S
WHERE NEW.carparkid = S.carparkid;

ELSEIF(WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 7)
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, S.per_entry, S.first_hour, S.hourly, S.every_30min, S.minute, S.start_time, S.end_time
FROM sunday_rates S
WHERE NEW.carparkid = S.carparkid;

ELSEIF(WEEKDAY(DATE_FORMAT(T.start_time, '%Y:%m:%d')) = 0 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 1 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 2 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 3 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 4 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 5 AND NEW.start_time  >= DATE_FORMAT(NEW.start_time, '%k:%i:%s') AND NEW.start_time <=DATE_FORMAT(NEW.start_time, '%k:%i:%s'))
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, W.per_entry, W.first_hour, W.hourly, W.every_30min, W.minute, W.start_time, W.end_time
FROM weekday_rates_2 W
WHERE NEW.carparkid = W.carparkid;

END IF;
END IF;
END
//
DELIMITER ;

这是我做的触发器,它工作正常,直到我意识到星期一(星期五)到星期五是0到4,所以我改变了这个

  DELIMITER //         
DROP TRIGGER IF EXISTS temp;
CREATE TRIGGER `temp` 
AFTER UPDATE ON charges 
FOR EACH ROW
BEGIN
IF(OLD.end_time IS NULL)
THEN
SET @parking_hours = TIMESTAMPDIFF(HOUR, NEW.start_time , NEW.end_time);
SET @parking_minutes = TIMESTAMPDIFF(MINUTE, NEW.start_time , NEW.end_time);
CALL check_booking(NEW.userid);
IF(WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 0 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 1 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 2 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 3 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 4 AND NEW.start_time  >= DATE_FORMAT(NEW.start_time, '%k:%i:%s') AND NEW.start_time <=DATE_FORMAT(NEW.start_time, '%k:%i:%s'))
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, W.per_entry, W.first_hour, W.hourly, W.every_30min, W.minute, W.start_time, W.end_time
FROM weekday_rates_1 W
WHERE NEW.carparkid = W.carparkid;

ELSEIF(WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 5)
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, S.per_entry, S.first_hour, S.hourly, S.every_30min, S.minute, S.start_time, S.end_time
FROM saturday_rates S
WHERE NEW.carparkid = S.carparkid;

ELSEIF(WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 6)
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, S.per_entry, S.first_hour, S.hourly, S.every_30min, S.minute, S.start_time, S.end_time
FROM sunday_rates S
WHERE NEW.carparkid = S.carparkid;

ELSEIF(WEEKDAY(DATE_FORMAT(T.start_time, '%Y:%m:%d')) = 0 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 1 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 2 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 3 OR WEEKDAY(DATE_FORMAT(NEW.start_time, '%Y:%m:%d')) = 4 AND NEW.start_time  >= DATE_FORMAT(NEW.start_time, '%k:%i:%s') AND NEW.start_time <=DATE_FORMAT(NEW.start_time, '%k:%i:%s'))
THEN
INSERT INTO temp (carparkid, time, hours, minutes, per_entry, first_hour, hourly, every_30min, minute, start_time, end_time) 
SELECT NEW.carparkid, NEW.start_time, @parking_hours, @parking_minutes, W.per_entry, W.first_hour, W.hourly, W.every_30min, W.minute, W.start_time, W.end_time
FROM weekday_rates_2 W
WHERE NEW.carparkid = W.carparkid;

END IF;
END IF;
END
//
DELIMITER ;

当我尝试使用新触发器进行更新时,它会给我这个错误。以下是一些其他相关表格。

CREATE TABLE charges
(tid VARCHAR(10), userid VARCHAR(10), carparkid VARCHAR(10), start_time DATETIME NOT NULL, end_time DATETIME, PRIMARY KEY (tid));
CREATE TABLE charges_seq
(id INT(10) AUTO_INCREMENT, PRIMARY KEY(id));
DELIMITER //
DROP TRIGGER IF EXISTS charges_insert;
CREATE TRIGGER charges_insert
BEFORE INSERT ON charges
FOR EACH ROW
BEGIN
INSERT INTO charges_seq VALUES (NULL);
SET NEW.tid = CONCAT('TID', LPAD(LAST_INSERT_ID(), 5, '0'));
END//
DELIMITER ;

INSERT INTO charges (userid, carparkid, start_time)
VALUES ('UID00003', 'CID00003', '2017-11-17 10:45:00');
UPDATE charges
SET end_time = '2017-11-17 18:00:00'
WHERE userid = 'UID00003';

右边,如果我只更改if条件,它不会影响任何东西吗?

0 个答案:

没有答案