下面的MySQL查詢打開多行的MySQL行成多列和單行
SELECT
`FBM_Orders`.`order-id`,
`FBM_Orders`.`purchase-date`,
`FBM_Orders`.`buyer-name`,
`FBM_Orders`.`sku`,
`IM_INV`.`LOC_ID`,
`IM_INV`.`QTY_ON_HND`
FROM
`FBM_Orders`
LEFT JOIN `IM_INV` ON `FBM_Orders`.`sku` = `IM_INV`.`ITEM_NO`
WHERE
`FBM_Orders`.`quantity-to-ship` > 0
ORDER BY
`FBM_Orders`.`purchase-date`,
`IM_INV`.`LOC_ID` ASC;
產生
| order-id | purchase-date | buyer-name | sku |LOC_ID|QTY_ON_HND|
|112-9548231-5585051|2017-09-11T21:34:27+00:00|Zacchary Motz|IE51198|AF | 2 |
|112-9548231-5585051|2017-09-11T21:34:27+00:00|Zacchary Motz|IE51198|LO | 1 |
|112-9548231-5585051|2017-09-11T21:34:27+00:00|Zacchary Motz|IE51198|S | 1 |
|112-9548231-5585051|2017-09-11T21:34:27+00:00|Zacchary Motz|IE51198|SL | 0 |
我已經有類似的問題的帖子看了看周圍,但他們都使用GROUP_CONCAT,並得到不同的結果比我正在尋找。我想知道如何得到的結果是
| order-id | purchase-date | buyer-name | sku | AF_QTY | LO_QTY | S_QTY | SL_QTY |
|112-95482..|2017-09-11T21...|Zacchary Motz|IE51198| 2 | 1 | 1 | 0 |
謝謝
AF,LO的
QTY_ON_HND
條件和您想要的結果, S&SL是這些固定值,或者可以有更多 –有時這是4或者沒有。 – enano2054