我目前正在使用电子表格来计算金融产品和地区之间的货币分配。下表是电子表格的一小部分,其中包含几百行数据和层次结构中的更多层:
+---------------+------------+---------------+------------+---------------+------------+---------------+------------+------------+------------+----------------+
| product_L1_id | Allocation | product_L2_id | Allocation | product_L3_id | Allocation | region_id | Allocation | country_id | Allocation | Net allocation |
+---------------+------------+---------------+------------+---------------+------------+---------------+------------+------------+------------+----------------+
| Bonds | 100.0% | Normal | 60.0% | Government | 70.0% | EMEA | 80.0% | UK | 30.0% | 10.1% |
| Bonds | 100.0% | Normal | 60.0% | Government | 70.0% | EMEA | 80.0% | France | 70.0% | 23.5% |
| Bonds | 100.0% | Normal | 60.0% | Government | 70.0% | North America | 20.0% | US | 0.0% | 0.0% |
| Bonds | 100.0% | Normal | 60.0% | Government | 70.0% | North America | 20.0% | Canada | 100.0% | 8.4% |
| Bonds | 100.0% | Normal | 60.0% | Corporate | 30.0% | EMEA | 60.0% | UK | 80.0% | 8.6% |
| Bonds | 100.0% | Normal | 60.0% | Corporate | 30.0% | EMEA | 60.0% | France | 20.0% | 2.2% |
| Bonds | 100.0% | Normal | 60.0% | Corporate | 30.0% | North America | 40.0% | US | 50.0% | 3.6% |
| Bonds | 100.0% | Normal | 60.0% | Corporate | 30.0% | North America | 40.0% | Canada | 50.0% | 3.6% |
| Bonds | 100.0% | Foreign | 40.0% | High yield | 80.0% | EMEA | 30.0% | UK | 60.0% | 5.8% |
| Bonds | 100.0% | Foreign | 40.0% | High yield | 80.0% | EMEA | 30.0% | France | 40.0% | 3.8% |
| Bonds | 100.0% | Foreign | 40.0% | High yield | 80.0% | North America | 70.0% | US | 30.0% | 6.7% |
| Bonds | 100.0% | Foreign | 40.0% | High yield | 80.0% | North America | 70.0% | Canada | 70.0% | 15.7% |
| Bonds | 100.0% | Foreign | 40.0% | Government | 20.0% | EMEA | 100.0% | UK | 0.0% | 0.0% |
| Bonds | 100.0% | Foreign | 40.0% | Government | 20.0% | EMEA | 100.0% | France | 100.0% | 8.0% |
| Bonds | 100.0% | Foreign | 40.0% | Government | 20.0% | North America | 0.0% | US | 70.0% | 0.0% |
| Bonds | 100.0% | Foreign | 40.0% | Government | 20.0% | North America | 0.0% | Canada | 30.0% | 0.0% |
+---------------+------------+---------------+------------+---------------+------------+---------------+------------+------------+------------+----------------+
值得我指出的是,同一product_L3
可以出现在不同的product_L2
下-以“政府”为例。
电子表格的主要输出是Net allocation
字段,它是所有单独分配的乘积。
我想将其转换为我的第一个数据库,并且在花很多时间实现它之前,请先检查一下自己的想法。在我看来,很明显有机会使用多个表,所以我第一次尝试使用schema(?):
product_L1
表,其中包含ID和分配列product_L2
表,其中包含ID和分配列product_L3
表,其中包含ID和分配列Region
表,其中包含ID和分配列Country
表,其中包含ID和分配列然后,我计划在每个表中使用外键将其链接到层次结构中的上一个表。但是,以Country
表为例-我认为这将需要每个国家重复多次,并且每条记录都必须具有所有先前表中的外键,以便查询得出{ {1}}。这是正确/有效吗?有其他不同的思考方式吗?我已经读过有关嵌套集的信息,但是不确定它们是否是这里的最佳解决方案?
这不会是多个用户的数据库-仅我一个。
答案 0 :(得分:1)
您的数据库设计对我来说很好。
一个人可能会说产品是一种产品,一个带有产品级别指示器的表就足够了,但是我认为带有三个表的这种模型是合适的。例如,它保证不能将1级产品用作2级产品。
缺少包含要显示的组合的表:
再次查看数据,我想到两件事。
这将得到如下内容: