Здравствуйте, у меня возникла проблема, потому что я хочу выбрать 3 разных значения из одной таблицы и отобразить их в разных столбцах в одной строке.
Я думаю, что это может быть достигнуто, но я не могу сделать это правильно.
Это таблица, из которой я хочу извлечь данные:
select * from mantis_custom_field_string_table limit 20 \G; *************************** 1. row ***************************
field_id: 4
bug_id: 1957
value: COCO-AB-00132
text: NULL
*************************** 2. row ***************************
field_id: 3
bug_id: 1957
value: COCO-AB-00132-100.220.181.65
text: NULL
*************************** 3. row ***************************
field_id: 7
bug_id: 1957
value: Lore Ipsum Lalala.
text: NULL
Это первый подход, который я пробую:
select summary,value from mantis_bug_table inner join mantis_custom_field_string_table on mantis_custom_field_string_table.bug_id=mantis_bug_table.id where (field_id=4 or field_id=3 or field_id=7) and id=1957;
+------------------------------------------+---------------------------------------------------------------------------------------------------------+
| summary | value |
+------------------------------------------+---------------------------------------------------------------------------------------------------------+
| This is the summary | COCO-AB-00132-100.220.181.65 |
| This is the summary | COCO-AB-00132 |
| This is the summary | Lore Ipsum Lalala. |
+------------------------------------------+-----------------------------------------------------------------------------------------
Вот что я хочу:
+------------------------------------------+---------------------------------------------------------------------------------------------------------+
| summary | ID | COCO | Lore |
+------------------------------------------+---------------------------------------------------------------------------------------------------------+
| This is the summary | COCO-AB-00132-100.220.181.65 | COCO-AB-00132 | Lore Ipsum Lalala |
И это я тоже пробовал, но безуспешно
mysql> select summary,value as ID, value as COCO, value as Lore from mantis_bug_table inner join mantis_custom_field_string_table on mantis_custom_field_string_table.bug_id=mantis_bug_table.id where (field_id=4 or field_id=3 or field_id=7) and id=1957 \G;
*************************** 1. row ***************************
summary: This is the summary
ID: COCO-RT-00132-100.220.181.65
COCO: COCO-RT-00132-100.220.181.65
Lore: COCO-RT-00132-100.220.181.65
*************************** 2. row ***************************
summary: This is the summary
ID: COCO-RT-00132
COCO: COCO-RT-00132
Lore: COCO-RT-00132
*************************** 3. row ***************************
summary: This is the summary
ID: This is the summary.
COCO: This is the summary.
Lore: This is the summary.
Я надеюсь, что кто-то может мне помочь с этим!