«

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

时间:2024-2-20 11:02     作者:韩俊     分类: 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)

标签: mysql

热门推荐