1. 事實表格(Fact Table)
事實表格 存儲的是業務事件或交易數據,通常包含數量、金額等度量值(Measures),以及與這些度量相關的外鍵(Foreign Keys),這些外鍵連接到維度表格。
例子:銷售事實表格(Sales Fact Table)
| Date Key |
Product Key |
Region Key |
Sales Quantity |
Sales Amount |
|---|
| 20200101 |
1 |
10 |
1000 |
5000 |
| 20200101 |
2 |
20 |
1500 |
7500 |
| 20200102 |
1 |
10 |
1200 |
6000 |
| ... |
... |
... |
... |
... |
- Date Key: 連接到日期維度表格,表示銷售發生的日期。
- Product Key: 連接到產品維度表格,表示銷售的產品。
- Region Key: 連接到地區維度表格,表示銷售發生的地區。
- Sales Quantity: 表示銷售的數量。
- Sales Amount: 表示銷售的金額。
2. 維度表格(Dimension Table)
維度表格 存儲的是業務中的描述性屬性,用於描述事實表中的數據。這些屬性提供了業務背景,用於數據的分類和分組。
例子1:日期維度表格(Date Dimension Table)
| Date Key |
Date |
Year |
Quarter |
Month |
Day |
|---|
| 20200101 |
2020-01-01 |
2020 |
Q1 |
Jan |
1 |
| 20200102 |
2020-01-02 |
2020 |
Q1 |
Jan |
2 |
| ... |
... |
... |
... |
... |
... |
- Date Key: 唯一標識日期的鍵。
- Date: 具體日期。
- Year: 年份。
- Quarter: 季度。
- Month: 月份。
- Day: 日期中的天。
例子2:產品維度表格(Product Dimension Table)
| Product Key |
Product Name |
Category |
Brand |
|---|
| 1 |
Green Tea |
Tea |
Brand A |
| 2 |
Black Tea |
Tea |
Brand B |
| ... |
... |
... |
... |
- Product Key: 唯一標識產品的鍵。
- Product Name: 產品名稱。
- Category: 產品類別。
- Brand: 產品品牌。
例子3:地區維度表格(Region Dimension Table)
| Region Key |
Region Name |
Country |
City |
|---|
| 10 |
North America |
USA |
New York |
| 20 |
Europe |
Germany |
Berlin |
| ... |
... |
... |
... |
- Region Key: 唯一標識地區的鍵。
- Region Name: 地區名稱。
- Country: 國家。
- City: 城市。