0

我的查询结果中有多行:

例如,表“附加”:

id_extras - id_order - id_size - name_extra - price

1           1          3         Teddy        4
2           2          8         Balloon      8
3           2          9         Wine         2
4           2          1         Choco        9
5           6          1         Bag          4

我真正想要的是:

id_extras - id_order - id_size - name_extra - price - name_extra1 - name_extra2 - price1 - price2

1           1          3         Teddy        4
2           2          8         Balloon      8       Wine          Choco         2        9
3           6          1         Bag          4

所以我需要name_extraandprice位于列而不是行中,我现在已经完成了。

SELECT  * ,
        MAX(CASE WHEN id_order = id_order THEN name_extra ELSE NULL END) name_extra1,
                MAX(CASE WHEN id_order = id_order THEN name_extra ELSE NULL END) name_extra2,
                MAX(CASE WHEN id_order = id_order THEN price ELSE NULL END) price1,
                MAX(CASE WHEN id_order = id_order THEN price ELSE NULL END) price2
FROM    extras 


GROUP   BY id_order
4

0 回答 0