赞
踩
@Author : Spinach | GHB
@Link : http://blog.csdn.net/bocai8058
针对数据仓库设计中表存储数据的方式而定义的,即记录历史。
记录一个事物从开始,一直到当前状态的所有变化的信息。
所以,任何一条记录(行数据)必定在历史上某天新生(start),
并在其后的某一天死亡(end),
那么这个start-end生存周期便定义为该记录的生命周期。
一般的数据表只会记录当前修改的时间,因此能得到某实体最新的状态快照
name | status | date |
---|---|---|
张三 | 1 | 2020-01-01 |
李四 | 5 | 2020-01-01 |
张三 | 3 | 2020-01-02 |
李四 | 6 | 2020-01-03 |
拉链表巧妙增加了产生(start_date)日期和死亡日期(start_date),用来回溯状态历史快照。
name | status | start_dt | end_dt |
---|---|---|---|
张三 | 1 | 2020-01-01 | 2020-01-01 |
李四 | 5 | 2020-01-01 | 2020-01-02 |
张三 | 3 | 2020-01-02 | _infinity |
李四 | 6 | 2020-01-03 | _infinity |
Select * from table where start_dt=<‘2020-01-02’ and end_dt>’2020-01-01’
name | status | start_dt | end_dt |
---|---|---|---|
李四 | 5 | 2020-01-01 | 2020-01-02 |
张三 | 3 | 2020-01-02 | _infinity |
Select * from table where end_dt=’_infinity’
name | status | start_dt | end_dt |
---|---|---|---|
张三 | 3 | 2020-01-02 | _infinity |
李四 | 6 | 2020-01-03 | _infinity |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。