[英]Populating fact table
I've a data warehouse for sales, it has 3 dimensions [product,time,store] and a fact table [sales_fact].我有一个销售数据仓库,它有 3 个维度 [产品、时间、商店] 和一个事实表 [sales_fact]。
Primary key of 'sales_fact' table is made up of all primary keys of dimensions table, dimension tables are all filled up manually now I want to fill 'sales_fact' table with SUM of prices of products stored in a city for a specific month or 3 month period. “sales_fact”表的主键由维度表的所有主键组成,维度表现在都是手动填写的月期间。
How should I sum up prices from product table which are related to a specific month and add it to fact table?我应该如何总结与特定月份相关的产品表中的价格并将其添加到事实表中?
Considering that sum up prices from product table which are related to a specific month is a measure, your query can be like below :考虑到与特定月份相关的产品表中的总价格是一种度量,您的查询可以如下所示:
SELECT DS.City, DT.[Month], SUM(DP.Price)FROM
SalesFact AS S
LEFT JOIN DimProduct AS DP ON DP.ProductSK=S.ProductSK
LEFT JOIN DimTime AS DT ON DT.DateSK=S.DateSK
LEFT JOIN DimStore AS DS ON DS.StoreSK=S.StoreSK
WHERE [Date condition] --Add your date conditoon
GROUP BY DS.City, DT.[Month]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.