热线电话:13121318867

登录
2020-08-05 阅读量: 1620
mysql怎么创建连续的日期列表

需求:想要创建从2020-5-1到2020-5-31的连续时间表

创建方法:

create or replace view generator10

as select 0 as n union all select 1 union all select 2 union all

select 3 union all select 4 union all select 5 union all

select 6 union all select 7 union all select 8 union all

select 9;

#创建视图1,返回的是0-9的序列表

image.png

create or replace view generator100

as select ( tens.n * 10 + ones.n ) as n

from generator10 ones

cross join generator10 tens

order by n;

#创建视图2,返回的是0-99的序列表

image.png

select ('2020-05-01' + interval n day) as dt

from generator100

where n between 0 and 30;
#生成结果

image.png

23.4776
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子