如何将两个事实 table 连接到一维 table

How to connect two fact tables to one dimensional table

我有两个事实 table(HistoricTable、ForecastTable)。 table 都使用将 productID 和 WeekID 组合在一起的组合键。 ForecastTable 有未来的 weekID 和历史的有以前的。我希望这两个 ProductID 都引用一个名为 ProductTable 的 Dimensional table。我如何连接它们?

我的假设是创建一个额外的 table,通过 UNION 连接查询 HistoricTable 和 ForecastTable,并将其连接到 ProductTable。这个逻辑对吗?

Table Image Layout

I want both of these ProductID's to reference one Dimensional table called ProductTable.

可以在historicproduct之间建立一个外键,在forecastproduct之间建立另一个外键。

例如:

create table product (
  id int primary key not null,
  name varchar(10)
);

create table historic (
  product_id int not null references product (id),
  week_id int not null,
  units_sold int,
  primary key (product_id, week_id)
);

create table forecast (
  product_id int not null references product (id),
  week_id int not null,
  forecast_units int,
  primary key (product_id, week_id)
);