MySql查询两个时间点之间的日期列表

 
更多

Mysql查询两个日期(时间点)之间的日期列表。

select * from
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where selected_date between '2021-02-25' and '2021-03-05';

返回结果如下:

+---------------+
| selected_date |
+---------------+
| 2021-02-25    |
| 2021-02-26    |
| 2021-02-27    |
| 2021-02-28    |
| 2021-03-01    |
| 2021-03-02    |
| 2021-03-03    |
| 2021-03-04    |
| 2021-03-05    |
+---------------+
9 rows in set (0.094 sec)
打赏

本文固定链接: https://www.cxy163.net/archives/3183 | 绝缘体

该日志由 绝缘体.. 于 2021年06月20日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: MySql查询两个时间点之间的日期列表 | 绝缘体
关键字: , , , ,

MySql查询两个时间点之间的日期列表:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter