我有3张桌子。
+---------+
| items |
+---------+
| item_id |
| ... |
+---------+
+----------------------+
| item_text_values |
+----------------------+
| item_text_value_id |
| item_id |
| custom_field_name_id |
| value |
+----------------------+
+----------------------+
| custom_field_names |
+----------------------+
| custom_field_name_id |
| index |
| name |
+----------------------+
item_text_values的计数未知。它可以是3个或10个或更多。我想有一个视图或存储过程,它返回带有变量列的行,具体取决于有多少个item_text_values记录。
我有经典的加入
SELECT *
FROM items
LEFT JOIN item_text_values ON item_text_values.item_id = items.item_id
LEFT JOIN custom_field_names ON custom_field_names.custom_field_name_id = item_text_values.custom_field_name_id
WHERE items.item_id = 1
如果有2条item_text_values记录,则返回2行。 我希望将这两行合并为一个具有可变列的行,具体取决于有多少item_text_values。不知道这是否可能。
谢谢