简体   繁体   English

事实表中的观察值也可以是维度吗?

[英]Can observations in a fact table also be dimensions?

My understanding is that a fact table uses keys, which are dimensions that ought to have their own dimension table, to identify observations and assign them values.我的理解是事实表使用键(应该有自己的维度表的维度)来识别观察结果并为其分配值。 Can these values themselves be dimensions?这些值本身可以是维度吗? Or does that violate some principle of a star schema?或者这是否违反了星型模式的某些原则?

For example, is this a valid fact table design?例如,这是一个有效的事实表设计吗?

Start Time开始时间 Stop Time停止时间 Employee ID员工ID Performance表现
01 01 60 60 0100 0100 Grade 3三年级
01 01 20 20 0200 0200 Grade 2 2年级
20 20 60 60 0200 0200 Grade 3三年级

My dimensions that I use to identify facts are the first three columns, with the final column being an observation.我用来识别事实的维度是前三列,最后一列是观察结果。 However, if I have more information about what each Performance means, does that mean that there needs to be a Performance dimension table?但是,如果我有更多关于每个 Performance 含义的信息,这是否意味着需要有一个 Performance 维度表? Or, because Performance is an observation rather than a dimension, does this data need to be in the fact table itself?或者,因为性能是一个观察而不是一个维度,所以这些数据是否需要在事实表本身中?

In a fact table there are normally 3 types of column:在事实表中,通常有 3 种类型的列:

  • measures: anything that can be aggregated措施:任何可以聚合的东西
  • dimension keys: key to a record in a dimension table维度键:维度表中记录的键
  • degenerate dimensions: attributes that do not naturally sit in a dimension (often because they would be the only attribute in the dimension)退化维度:不自然地位于维度中的属性(通常是因为它们将是维度中的唯一属性)

It is also possible for an attribute to be both a measure in a fact table and an attribute in a dimension.一个属性也可以既是事实表中的度量,又是维度中的属性。 For example, the price of a product could be both a measure in a fact table and an attribute in the product dimension例如,产品的价格既可以是事实表中的度量,也可以是产品维度中的属性

Does this help?这有帮助吗?

Update更新

Say you wanted to know the average price of the products you have sold: in this case product price is a measure and lives in a sales fact table;假设您想知道已售出产品的平均价格:在这种情况下,产品价格是一种衡量标准,存在于销售事实表中; that fact table would almost certainly have an FK to your Product Dimension - so you could filter on product attributes eg average price of product for products whose category = "Food".该事实表几乎肯定会对您的产品维度具有 FK - 因此您可以过滤产品属性,例如类别 =“食品”的产品的平均价格。

You might also want to filter a query based on product price: in this case product price is an attribute in your product dimension (which would probably be an SCD2 dimension to cater for price changes).您可能还想根据产品价格过滤查询:在这种情况下,产品价格是您的产品维度中的一个属性(可能是满足价格变化的 SCD2 维度)。 For example, you might want to query your stock-level fact table (which doesn't hold product prices as measures but does have an FK to the product dimension) for all products whose price is between £10 and £20例如,您可能想要查询价格在 10 英镑到 20 英镑之间的所有产品的库存级事实表(它不将产品价格作为度量,但对产品维度有 FK)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM