2

我们希望更新此示例数据库中的日期,使其看起来更近。将每个季度代码增加 5 年,使 19964 看起来像 20014。通过在表中显示数据来验证您的结果。我正在使用 mySQL Oracle 命令行客户端,想知道如何将所有 interviewdate 记录更新 5 年。

interview table
+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| interviewdate | date         | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+

interviewdate column
+---------------+
| interviewdate |
+---------------+
| 1995-06-01    |
| 1995-06-01    |
| 1995-06-30    |
| 1995-06-30    |
| 1995-07-01    |
| 1995-08-01    |
| 1995-08-01    |
| 1995-08-02    |
| 1995-12-01    |
| 1995-12-02    |
| 1995-12-04    |
| 1996-01-21    |
| 1996-02-01    |
| 1996-02-02    |
| 1996-07-01    |
| 1996-07-01    |
| 1996-08-01    |
| 1996-08-08    |
| 1996-08-11    |
| 1997-01-01    |
| 1997-01-01    |
| 1997-01-31    |
| 1997-02-01    |
| 1997-03-24    |
| 1997-03-31    |
| 1997-04-20    |
| 1997-04-22    |
| 1997-05-01    |
+---------------+
28 rows in set (0.00 sec)

我试过这样的事情:

UPDATE interview
SET qtrcode = DATEADD(year, 5, qtrcode);
ERROR 1305 (42000): FUNCTION jobs.DATEADD does not exist
4

1 回答 1

4

这应该有效:

update interview
set interviewdate = date_add(interviewdate, interval 5 year);

http://sqlfiddle.com/#!2/55ab7/1

于 2013-07-22T00:56:29.327 回答