我计划在现有多维数据集中基于生产数据库创建维Location
。问题是这个数据库包含一个带有自引用对象的层次结构,一个名为locations:
+----+----------+------------+
| id | parentId | name |
+----+----------+------------+
| 1 | NULL | Building A |
+----+----------+------------+
| 2 | 1 | Floor 1 |
+----+----------+------------+
| 3 | 2 | Room 11 |
+----+----------+------------+
| 4 | 2 | Room 12 |
+----+----------+------------+
| 5 | 2 | Room 13 |
+----+----------+------------+
| 6 | 1 | Floor 2 |
+----+----------+------------+
| 7 | 6 | Room 21 |
+----+----------+------------+
| 8 | 6 | Room 22 |
+----+----------+------------+
| 9 | NULL | Building B |
+----+----------+------------+
| 10 | 9 | Room 1 |
+----+----------+------------+
| 11 | 9 | Room 2 |
+----+----------+------------+
| 12 | 9 | Room 3 |
+----+----------+------------+
| 13 | NULL | Storage |
+----+----------+------------+
| 14 | NULL | Reception |
+----+----------+------------+
通常我会创建一个类似日期的层次结构,属性月份是属性日期的父级,属性年份是属性月份的父级。但是,在这种情况下,维度Name
中的属性Location
可能是另一个Name
的父级。
如何从这些记录中创建层次结构?