尝试使用DATEADD并获取函数不存在错误

时间:2017-05-08 03:25:38

标签: mysql sql phpmyadmin

我的表TableName包含大约5,000行。它由product_idScheduleTime组成。

我想要对此表做的是替换ScheduleTime的每个值,无论它当前是什么。每个记录的ScheduleTime新值应设置为前一记录后20分钟的被提名值,但有以下例外情况。如果被提名者ScheduleTime出现在22:30:00之后或05:00:00之前(即为时已晚或过早),则应将其设置为下一个可用的日期时间。

我应该可以指定ScheduleTime的第一个新值。

这是我目前正在使用的查询...

UPDATE TableName 
SET ScheduleTime = DATEADD( MI, ScheduleTime, 20 ) 
WHERE CAST( ScheduleTime AS TIME ) >= '22:30:00' 
   OR CAST( ScheduleTime AS TIME ) < '05:00:00';

但它正在产生此错误消息......

#1305 - FUNCTION DatabaseName.DATEADD does not exist

此查询可用于创建我拥有的表...

CREATE TABLE IF NOT EXISTS TableName
(
    product_id VARCHAR( 255 ) NOT NULL,
    ScheduleTime DATETIME NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

我使用以下示例数据填充上表...

INSERT INTO TableName ( product_id,
                        ScheduleTime )
VALUES ( '01', '2017-05-07 22:00:59' ),
       ( '02', '2017-05-07 09:09:59' ),
       ( '03', '2017-05-07 09:59:59' ),
       ( '04', '2017-05-07 09:49:59' ),
       ( '05', '2017-05-07 23:09:59' ),
       ( '06', '2017-05-07 23:09:59' ),
       ( '07', '2017-05-07 23:09:59' ),
       ( '08', '2017-05-07 23:09:59' ),
       ( '09', '2017-05-07 23:09:59' ),
       ( '10', '2017-05-07 23:09:59' ),
       ( '11', '2017-05-07 23:09:59' ),
       ( '12', '2017-05-07 23:09:59' ),
       ( '13', '2017-05-07 23:09:59' ),
       ( '14', '2017-05-07 23:09:59' ),
       ( '15', '2017-05-07 23:09:59' ),
       ( '16', '2017-05-07 23:09:59' ),
       ( '17', '2017-05-07 23:09:59' ),
       ( '18', '2017-05-07 23:09:59' ),
       ( '19', '2017-05-07 23:09:59' ),
       ( '20', '2017-05-07 23:09:59' );

0 个答案:

没有答案