如何从表中提取信息以填充已创建数据仓库中的日历表

jutyujz0  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(270)

我有一个事务表,它的一个重要列被标记为 TDate .
我需要使用此列信息来创建 Calendar table。 TDate 例子: 2013-1-1Calendar Table ,我一定有 Month , Day , Year 在不同的列中。这样做的语法是什么?

bfnvny8b

bfnvny8b1#

试试这个,我想你在找。它只是一个简单的使用年,月,日函数提取所有这些值并插入到不同的表中,如下所示。

create table test_2(TDate date);
insert into test_2 values(now());
select * from test_2;
create table calendar(year int, month int, day int);
insert into calendar select year(tdate) as year,month(tdate) as month, day(tdate) as day from test_2;

    mysql> select * from calendar;
    +------+-------+------+
    | year | month | day  |
    +------+-------+------+
    | 2018 |     5 |    5 |
    +------+-------+------+
    1 row in set (0.00 sec)

相关问题