我想将三个表联合到一个查询,如数据透视表。我的主表名是 products,两个支持表名是 code_keys 和 code_values
我有一个主表名: products
+------------------+
| Field |
+------------------+
| productid |
| catpath |
| da |
| l0 |
| ig |
| des |
| notes |
| wire |
| lmm |
+------------------+
示例数据:
+-----------+------+------+------+
| productid | da | ig | des |
+-----------+------+------+------+
| 5 | 78 | 33 | 23 |
| 8 | 88 | 13 | 21 |
+-----------+------+------+------+
和 2 个 conf 表名:code_keys。存储代码结构。
+--------+
| Field |
+--------+
| codeid |
| title |
| codekey|
| format |
+--------+
示例数据:
+--------+----------------+
| codeid | title |
+--------+----------------+
| 2 | St Code |
| 3 | Rear Les |
+--------+----------------+
代码值
+-------+
| Field |
+-------+
| id |
| pid | -> Product ID
| codeid|
| value |
+-------+
最后是示例数据:
+----+------+--------+--------------+
| id | pid | codeid | value |
+----+------+--------+--------------+
| 9 | 5 | 2 | ST 102 200 R |
| 10 | 5 | 3 | 12 000 33 |
| 11 | 6 | 2 | ST 343 432 R |
| 12 | 6 | 3 | 34 343 24 |
| 15 | 8 | 2 | ST 100 101 R |
| 16 | 8 | 3 | 11 223 34 |
| 17 | 0 | 2 | ST 343 432 R |
| 18 | 0 | 3 | 34 343 24 |
+----+------+--------+--------------+
我想在一个查询中显示这样的内容:
产品专栏 | *code_keys 行 > 列* |
+-----------+------+------+------+--------------+----------+
| productid | da | ig | des | St Code | Rear Les |
+-----------+------+------+------+--------------+----------+
| 5 | 78 | 33 | 23 | ST 102 200 R | 12 000 33|
| 8 | 88 | 13 | 21 | ST 100 101 R | 11 223 34|
+-----------+------+------+------+--------------+----------+
有任何想法吗?