返回顶部

收藏

mysql 日期相加

更多
mysql> CREATE   TABLE COMMITTEE_MEMBERS
    ->         (EmployeeNO       INTEGER      NOT NULL,
    ->          BEGIN_DATE     DATE         NOT NULL,
    ->          END_DATE       DATE                 ,
    ->          POSITION       CHAR(20)             ,
    ->          PRIMARY KEY    (EmployeeNO, BEGIN_DATE));
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6, '1990-01-01', '1990-12-31', 'Secretary');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6, '1991-01-01', '1992-12-31', 'Member');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6, '1992-01-01', '1993-12-31', 'Treasurer');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  6, '1993-01-01',  NULL, 'Chairman');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  2, '1990-01-01', '1992-12-31', 'Chairman');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  2, '1994-01-01',  NULL, 'Member');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (112, '1992-01-01', '1992-12-31', 'Member');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (112, '1994-01-01',  NULL, 'Secretary');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8, '1990-01-01', '1990-12-31', 'Treasurer');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8, '1991-01-01', '1991-12-31', 'Secretary');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8, '1993-01-01', '1993-12-31', 'Member');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES (  8, '1994-01-01',  NULL, 'Member');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES ( 57, '1992-01-01', '1992-12-31', 'Secretary');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES ( 27, '1990-01-01', '1990-12-31', 'Member');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES ( 27, '1991-01-01', '1991-12-31', 'Treasurer');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES ( 27, '1993-01-01', '1993-12-31', 'Treasurer');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO COMMITTEE_MEMBERS VALUES ( 95, '1994-01-01',  NULL, 'Treasurer');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql>
mysql> SELECT   EmployeeNO, BEGIN_DATE,
    ->          BEGIN_DATE + INTERVAL 2 MONTH + INTERVAL 3 DAY
    -> FROM     COMMITTEE_MEMBERS;
+------------+------------+------------------------------------------------+
| EmployeeNO | BEGIN_DATE | BEGIN_DATE + INTERVAL 2 MONTH + INTERVAL 3 DAY |
+------------+------------+------------------------------------------------+
|          2 | 1990-01-01 | 1990-03-04                                     |
|          2 | 1994-01-01 | 1994-03-04                                     |
|          6 | 1990-01-01 | 1990-03-04                                     |
|          6 | 1991-01-01 | 1991-03-04                                     |
|          6 | 1992-01-01 | 1992-03-04                                     |
|          6 | 1993-01-01 | 1993-03-04                                     |
|          8 | 1990-01-01 | 1990-03-04                                     |
|          8 | 1991-01-01 | 1991-03-04                                     |
|          8 | 1993-01-01 | 1993-03-04                                     |
|          8 | 1994-01-01 | 1994-03-04                                     |
|         27 | 1990-01-01 | 1990-03-04                                     |
|         27 | 1991-01-01 | 1991-03-04                                     |
|         27 | 1993-01-01 | 1993-03-04                                     |
|         57 | 1992-01-01 | 1992-03-04                                     |
|         95 | 1994-01-01 | 1994-03-04                                     |
|        112 | 1992-01-01 | 1992-03-04                                     |
|        112 | 1994-01-01 | 1994-03-04                                     |
+------------+------------+------------------------------------------------+
17 rows in set (0.00 sec)

mysql>
mysql> drop table COMMITTEE_MEMBERS;
Query OK, 0 rows affected (0.00 sec)

mysql>

标签:mysql,sql,date

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. 胡 志伟 发表 2014-04-09 09:37:26 Mysql存储过程计算留存率
  2. sulong 发表 2010-07-20 13:50:18 一次sql调优
  3. surenkid 发表 2015-03-31 02:54:24 SQL Server连接Mysql服务器配置
  4. Specs 发表 2015-08-11 03:14:23 20+条MySQL性能优化的最佳经验
  5. admin 发表 2016-03-23 05:00:24 SQL注入速查表(上)
  6. yeseng 发表 2016-04-04 14:55:45 谈数据稽核(3)
  7. 蓝鲸 发表 2017-10-20 06:37:49 像Excel一样使用SQL进行数据分析(1)
  8. 蓝鲸 发表 2017-11-03 02:29:21 像Excel一样使用SQL进行数据分析(3)
  9. 尖兵 发表 2018-03-06 15:45:56 mysql报错ERROR 1093
  10. Specs 发表 2015-08-11 05:42:17 运维角度浅谈MySQL数据库优化
  11. justwinit <xdy108@12 发表 2015-12-04 00:01:09 Linux系统区别英文字母大小写,从Windows上迁移MySQL到linux忽略SQL表大小写参数
  12. ITJesse 发表 2014-01-05 20:06:56 将SQL Server中的数据导入MySQL