How to connect a fact and dimension table that are in 1-N relationship

大兔子大兔子 提交于 2019-12-08 15:17:36

My experience will favor a design with two fact tables purchase and pruchase_detail.

PURCHASE has one row per purchase with attributes

 purchase_id  -- unique ID 
 purchase_date  
 customer_id
 ...

PURCHASE_DETAIL has 1:N row per purchase and store the pricing details.

 purchase_id -- corresponding purchase
 account_type -- dimension describing sales price and all discount types
 amount
 ....

The amount has a proper sign; sales price positive, discounts negative.

Example

 purchase_id    account_type    amount
 1              sales price     100
 1              discount1       -5
 1              discount2       -1

With this design, you may safely COUNT purchases (on PURCHASE table), SUM total prices (on PURCHASE_DETAIL) and make all kind or detailed discount reports.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!