博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 根据日期时间查询数据
阅读量:4962 次
发布时间:2019-06-12

本文共 6092 字,大约阅读时间需要 20 分钟。

 

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)

 

 

 

 

转载于:https://www.cnblogs.com/sea-stream/p/11299667.html

你可能感兴趣的文章
mysql 生成随机数rand()
查看>>
mysql e的n次幂exp()
查看>>
mysql sin() 函数
查看>>
mysql upper() 函数
查看>>
mysql 子查询
查看>>
mysql 自联结
查看>>
mysql union 组合查询
查看>>
socket tcp
查看>>
spiral-matrix-ii &i 生成顺时针序列
查看>>
三大WEB服务器对比分析(apache ,lighttpd,nginx)
查看>>
关于STC单片机的内存管理
查看>>
1025: [SCOI2009]游戏 - BZOJ
查看>>
python set集合方法总结
查看>>
python考点
查看>>
dstat 监控时,无颜色显示
查看>>
CSS3阴影 box-shadow的使用和技巧总结
查看>>
DataMining--Python基础入门
查看>>
单片机复位电路
查看>>
php json_decode失败,返回null
查看>>
获取单选按钮选中的值
查看>>