我有三张桌子,上面有人物、属性和属性的潜在价值。我想不出一个查询来显示所有人、每个人的属性及其缺失/空属性。
这是一个示例表...
attributes
+---------------------+
| attribute_name (col)|
+---------------------+
| name |
+---------------------+
| age |
+---------------------+
| gender |
+---------------------+
| email |
+---------------------+
people
+-----------+----------+
| person_id | value_id |
+-----------+----------+
| 2 | 7 |
+-----------+----------+
| 2 | 9 |
+-----------+----------+
| 3 | 8 |
+-----------+----------+
values
+---------------+----------------+-------+
| value_id (pk) | attribute_name | value |
+---------------+----------------+-------+
| 7 | age | 35 |
+---------------+----------------+-------+
| 8 | age | 28 |
+---------------+----------------+-------+
| 9 | gender | male |
+---------------+----------------+-------+
如何加入三个表以显示这样的内容?
+-----------+----------+-----------------+--------+
| person_id | value_id | attribute_name | value |
+-----------+----------+-----------------+--------+
| 2 | 7 | age | 35 |
+-----------+----------+-----------------+--------+
| 2 | 9 | gender | male |
+-----------+----------+-----------------+--------+
| 2 | NULL | name | NULL |
+-----------+----------+-----------------+--------+
| 2 | NULL | email | NULL |
+-----------+----------+-----------------+--------+
| 3 | 8 | age | 28 |
+-----------+----------+-----------------+--------+
| 3 | NULL | gender | NULL |
+-----------+----------+-----------------+--------+
| 3 | NULL | name | NULL |
+-----------+----------+-----------------+--------+
| 3 | NULL | email | NULL |
+-----------+----------+-----------------+--------+