1

如何从关系源填充 Dim_tbls?

给出了这些示例表:

tbl_sales:    id_sales, fk_id_customer, fk_id_product, country, timestamp   
tbl_customer: id_customer, name, adress, zip, city
tbl_product:  id_product, price, product

我的目标是将这些属性放入启动模式中。我遇到的问题是加载维度表背后的逻辑。我的意思是,我会将哪些数据加载到 Dim_Product 中?tbl_product 中的所有产品?但是我怎么知道特定产品完成了多少销售呢?

我想做的分析是:

 How many people bought product x.
 How many sales are made from city x.
 How many sales were made between Time x and y. 

示例数据:

 tbl_sales: id_sales | fk_id_customer | fk_id_product | country | timestamp 
                1    |       2        |      1        |   UK    | 19.11.2013 10:23:22
                2    |       1        |      2        |   FR    | 20.11.2013 06:04:22

 tbl_customer: id_customer | name | adress | zip | city
                      1    | Frank|Street X| 211 | London
                      2    | Steve|Street Y| 431 | Paris

 tbl_customer: id_product| Price | product
                      1  | 100,00| Hammer
                      2  |  50,00| Saw
4

1 回答 1

2

让我们从一个非常简单的星型模式模型开始;例如,我假设您不必担心处理维度属性的更改。

事实销售

  DateKey
  CustomerKey
  ProductKey
  Counter (=1; this is a factless fact table)

昏暗日期

  DateKey
  Date
  Year
  Quarter
  Month
  ...

昏暗客户

  CustomerKey
  Name
  Address
  Zip
  City

昏暗产品

  ProductKey
  Name
  Price (if it changes, you need move it to factSales)

有多少人购买了产品 x。

SELECT DISTINCT CustomerKey
FROM factSales
WHERE ProductKey IN ( SELECT ProductKey
                      FROM dimProduct
                      WHERE Name = 'Product X' )

有多少来自城市 x 的销售额。

SELECT SUM(Counter)
FROM factSales
WHERE CustomerKey IN ( SELECT CustomerKey
                       FROM dimCustomer
                       WHERE City = 'City X' )

在时间 x 和 y 之间进行了多少销售。

SELECT SUM(Counter)
FROM factSales
WHERE DateKey IN ( SELECT DateKey
                   FROM dimDate
                   WHERE Date BETWEEN DateX AND DateY )
于 2013-10-08T19:32:07.583 回答