事实表的数据仓库设计

Data Warehouse Design of Fact Tables

我是数据仓库设计的新手,并且正在为如何设计事实而苦苦挣扎 table 给定非常相似但有些不同的指标。假设您正在评估以下指标,您将如何分解事实 tables(在这种情况下,公司是客户的一个子集)。您是否可以对所有这些使用一个 table,或者每个被衡量的指标是否可以保证其自身的事实 table,或者被衡量的指标的每个部分是否会在一个事实中成为其自己的列 table?

从度量名称的外观来看,我认为您会得到一个事实 table,其中每个文件都有一条记录,并且 link 返回 date_dim

create table date_dim (
    date_sk        int,
    calendar_date  date,
    month_ordinal  int,
    month_name     nvarchar,
    Year           int,
..etc you've got your own one of these ..
)
create table fact_file_measures (
    date_sk,
    file_sk,           --ref the file_dim with additonal file info
    company_sk,        --ref the company_dim with the client details
    processed  int,    --should always be one, optional depending on how your reporting team like to work
    size_Kb    decimal -- specifiy a size measurement, ambiguity is bad
    error_count int    -- 1 if file had error, 0 if fine
    failed_count int   -- 1 or file failed, 0 if fine
)

所以现在您应该能够构建查询来获取您所要求的一切

例如,对于您的每月统计数据:

select 
    c.company_name,
    c.client_name,
    sum(f.file_count) total_files,
    sum(f.size_Kb)    total_files_size_Kb,
    sum(f.file_count) total_files,
    sum(f.file_count) total_files
from
    fact_file_measure f
    inner join dim_company c on f.company_sk = c.company_sk
    inner join dim_date d on f.date_sk = d.date_sk
where
    d.month = 'January' and d.year = "1984"

如果您需要并排 'day/month/year' 的东西,您可以构建年份和月份事实 table 来进行汇总并通过 dim_date 加入month/year 个字段。 (您可以在每日事实中包含月份和年份字段 table,但这些值最终可能会被经验不足的报表制作者误用)这一切都可以追溯到您的用户真正想要的 - 设计您的事实 tables 满足他们的要求,不要害怕有单独的事实 tables - 数据仓库与规范化无关,它是以一种可以使用的方式呈现数据。

祝你好运