zoukankan      html  css  js  c++  java
  • mysql 根据日期时间查询数据

    mysql> select * from table1;
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    | 3hahha   | lee        |   6 | 2019-08-04 20:46:12 |
    +----------+------------+-----+---------------------+
    6 rows in set (0.01 sec)
    
    mysql> select * from table1 where minute(order_date)=46;
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    | 3hahha   | lee        |   6 | 2019-08-04 20:46:12 |
    +----------+------------+-----+---------------------+
    4 rows in set (0.00 sec)
    
    mysql> select * from table1 where second(order_date) between 2 and 12;
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    | 3hahha   | lee        |   6 | 2019-08-04 20:46:12 |
    +----------+------------+-----+---------------------+
    4 rows in set (0.00 sec)
    
    mysql> select * from table1 where second(order_date) between 2 and 9;
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    +----------+------------+-----+---------------------+
    3 rows in set (0.00 sec)
    mysql> select * from table1;
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    | 3hahha   | lee        |   6 | 2019-08-04 20:46:12 |
    +----------+------------+-----+---------------------+
    6 rows in set (0.01 sec)
    
    
    
    mysql> select * from table1 where date(order_date)='2019-08-04';
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    | 3hahha   | lee        |   6 | 2019-08-04 20:46:12 |
    +----------+------------+-----+---------------------+
    6 rows in set (0.00 sec)
    
    
    
    mysql> select * from table1 where date(order_date) between '2019-08-04' and '2019-08-04';
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    | 3hahha   | lee        |   6 | 2019-08-04 20:46:12 |
    +----------+------------+-----+---------------------+
    6 rows in set (0.00 sec)
    
    
    
    mysql> select * from table1 where order_date between '2019-08-04 20:45:47' and '2019-08-04 20:46:08';
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    +----------+------------+-----+---------------------+
    5 rows in set (0.00 sec)
    
    
    
    mysql> select * from table1 where time(order_date) between '20:45:47' and '20:46:08';
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    +----------+------------+-----+---------------------+
    5 rows in set (0.00 sec)
    
    
    
    mysql> select * from table1 where time(order_date)='20:46:02';
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    +----------+------------+-----+---------------------+
    1 row in set (0.00 sec)
    mysql> select * from table1 where time(order_date) between "20:45:47" and "20:46:08";
    +----------+------------+-----+---------------------+
    | name_new | transactor | pid | order_date          |
    +----------+------------+-----+---------------------+
    | 1hahha   | 1xiaohong  |   1 | 2019-08-04 20:45:47 |
    | 2hahha   | 2xiaohong  |   2 | 2019-08-04 20:45:57 |
    | 3hahha   | 3xiaohong  |   3 | 2019-08-04 20:46:02 |
    | 4hahha   | 4xiaohong  |   4 | 2019-08-04 20:46:05 |
    | 3hahha   | bob        |   5 | 2019-08-04 20:46:08 |
    +----------+------------+-----+---------------------+
    5 rows in set (0.00 sec)

  • 相关阅读:
    rabbitmq报错:not_a_dets_file,"/var/lib/rabbitmq/mnesia/rabbit@Sfabrici-Demo01/recovery.dets"的解决办法
    ubuntu18上关闭默认的防火墙
    《GCD宣言》全文
    springboot日志配置
    springboot打jar包【我】
    MongoDB 4.2 用户管理
    【短道速滑四】Halcon的texture_laws算子自我研究
    Android集合之SparseArray、ArrayMap详解
    浅析微信支付:下载对账单和资金账单
    学习如修行
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11299667.html
Copyright © 2011-2022 走看看