这是表格:TABLE1
ID | id_activity | id_elem | text
---------------------------------------
1 | 1 | 11 | text1 |
2 | 1 | 12 | text2 |
3 | 1 | 13 | text3 |
4 | 2 | 11 | text4 |
5 | 2 | 12 | text5 |
6 | 2 | 13 | text6 |
7 | 3 | 11 | text7 |
8 | 3 | 12 | text8 |
9 | 3 | 13 | text9 |
10 | 4 | 11 | text10 |
11 | 4 | 12 | text11 |
12 | 4 | 13 | text12 |
13 | 5 | 11 | text13 |
14 | 5 | 12 | text14 |
15 | 5 | 13 | text15 |
16 | 6 | 11 | text16 |
17 | 6 | 12 | text17 |
18 | 6 | 13 | text18 |
我需要做出这样的结果:
ID | text_elem_11 | text_elem_12 | text_elem_13
---------------------------------------------------
1 | text1 | text2 | text3 |
2 | text4 | text5 | text6 |
3 | text7 | text8 | text9 |
4 | text10 | text11 | text12 |
5 | text13 | text14 | text15 |
6 | text16 | text17 | text18 |
这样做的正确方法是什么?通过以下查询,我只能得到一个包含第一列和第二列的表
SELECT table1.ID,
table1.id_elem,
elem_11.text AS text_elem_11
FROM table1
INNER JOIN table1 AS elem_11 ON
table1.id_activity = 1 AND
table1.id_elem = 11 AND
elem_11.id_elem = 11
这是结果
id_activity | id_elem | text_elem_11 |
-----------------------------------------
1 | 11 | text1 |
1 | 11 | text4 |
1 | 11 | text7 |
我不知道如何添加其他 2 列,如果用一个查询来做是个好主意……那么,有什么想法吗?