首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在我的数据仓库中计算维度表的数量

在我的数据仓库中计算维度表的数量
EN

Stack Overflow用户
提问于 2015-07-21 22:13:13
回答 2查看 183关注 0票数 1

我是一个数据仓库新手,所以请轻松一点。

在这种情况下,我试图找出维数。

在我的事务数据库中:

  • 我有一张桌子可以存储位置代码。列是location_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null
  • 我有一张存储区域代码的桌子。列是region_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null
  • 我有一张把地点和地区联系起来的桌子。列是assoc_id int not null primary key, location_code int not null, region_code int not null。一个地点只属于一个区域。

在我的数据仓库数据库中,用户可能希望按位置或区域查找数据。

现在,我希望在本例中创建维度表。

想知道我是否应该以这种方式创建二维表(一个用于位置,一个用于区域)?

  • 为位置创建一维表,该表也具有以下列的区域:location_code int not null primary key, location_short_description varchar(10) not null, location_long_description varchar(100) not null, region_code int not null, region_short_description varchar(10) not null, region_long_description varchar(100) not null
  • 为同样具有以下列的位置的区域创建一维表:region_code int not null primary key, region_short_description varchar(10) not null, region_long_description varchar(100) not null, location_code int not null, location_short_description varchar(10) not null, location_long_description varchar(100) not null

或者应该以这种方式创建4个维度表(1个用于位置,1个用于区域,1个用于位置区域关联,1个用于区域位置关联)?

  • 创建具有以下列的位置的一维表:location_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null
  • 使用以下列为区域创建一维表:region_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null
  • 为与这些列关联的位置区域创建一维表:location_code int not null, region_code int not null
  • 为区域位置创建与以下列关联的一维表:region_code int not null, location_code int not null

还是有其他更有意义的方法?如果是,请告诉

在数据仓库世界中,这被称为什么类型的关系,以及处理它的标准方法是什么?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-22 18:08:28

我将在同一维度(根据业务使用情况命名,例如D_Location或D_Geography)对位置和区域进行建模。

事实表中将包含小时数,事实表F_Hour和D_Location将与代理键连接( Oracle中的序列或server中的标识)。

对于区域和位置的所有描述列都可以愉快地在D_Location中居住(当然,区域不会被规范化,但通常是这样做的)。

票数 0
EN

Stack Overflow用户

发布于 2015-07-22 20:02:53

我认为您不需要在维度表中跟踪位置和区域的关联。这种关联可以出现在事实表中。

我将创建二维表D_Location & D_Region和1个事实表F_Hour

D_Location:

代码语言:javascript
运行
复制
location_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null

D_Region:

代码语言:javascript
运行
复制
region_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null

F_Hour:

代码语言:javascript
运行
复制
hour_id int not null primary key, location_code int not null, region_code int not null, hours decimal(10,2) not null

F_Hour为1 FK至D_Location,1 FK为D_Region

要获得特定location_code (@location_code)的小时数:

代码语言:javascript
运行
复制
select h.location_code, l.short_description, l.long_description, sum(h.hours) 
from F_Hour h inner join D_Location l on h.location_code = l.location_code 
where h.location_code = @location_code 
group by h.location_code, l.short_description, l.long_description 
order by h.location_code

要获得特定region_code (@region_code)的小时数:

代码语言:javascript
运行
复制
select h.region_code, r.short_description, r.long_description, sum(h.hours) 
from F_Hour h inner join D_Region r on h.region_code = r.region_code 
where h.region_code = @region_code 
group by h.region_code, r.short_description, r.long_description 
order by h.region_code

说得通吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31550554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档