返回顶部

收藏

mysql实现日期加时间段

更多
mysql>
mysql> CREATE   TABLE PENALTIES
    ->         (PAYMENTNO      INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          PAYMENT_DATE   DATE         NOT NULL,
    ->          AMOUNT         DECIMAL(7,2) NOT NULL,
    ->          PRIMARY KEY    (PAYMENTNO)          );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO PENALTIES VALUES (1,  6, '1980-12-08',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (2, 44, '1981-05-05', 75);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (3, 27, '1983-09-10',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (4,104, '1984-12-08', 50);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (5, 44, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (6,  8, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (7, 44, '1982-12-30', 30);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (8, 27, '1984-11-12', 75);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql>
mysql> SELECT   PAYMENTNO, PAYMENT_DATE,
    ->          PAYMENT_DATE + INTERVAL 3 HOUR +
    ->          INTERVAL 50 SECOND + INTERVAL 99 MICROSECOND
    -> FROM     PENALTIES;
+-----------+--------------+-----------------------------------------------------------------------------------------+
| PAYMENTNO | PAYMENT_DATE | PAYMENT_DATE + INTERVAL 3 HOUR +
         INTERVAL 50 SECOND + INTERVAL 99 MICROSECOND |
+-----------+--------------+-----------------------------------------------------------------------------------------+
|         1 | 1980-12-08   | 1980-12-08 03:00:50.000099                                                              |
|         2 | 1981-05-05   | 1981-05-05 03:00:50.000099                                                              |
|         3 | 1983-09-10   | 1983-09-10 03:00:50.000099                                                              |
|         4 | 1984-12-08   | 1984-12-08 03:00:50.000099                                                              |
|         5 | 1980-12-08   | 1980-12-08 03:00:50.000099                                                              |
|         6 | 1980-12-08   | 1980-12-08 03:00:50.000099                                                              |
|         7 | 1982-12-30   | 1982-12-30 03:00:50.000099                                                              |
|         8 | 1984-11-12   | 1984-11-12 03:00:50.000099                                                              |
+-----------+--------------+-----------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)

mysql>
mysql> drop table PENALTIES;
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