嗨需要一些幫助,MySQL查詢MySQL查詢優化
我的數據是,像這樣
Table base_status
| id | order_id | status | dt_added |
-------------------------------------
| 1 | 123 | xyz | date3 |
| 2 | 123 | abc | date2 |
| 3 | 123 | pqr | date1 |
我試圖讓輸出等
| order_id | xyz_date | abc_date | pqr_date |
-------------------------------------------
| 123 | date3 | date2 | date3 |
MySQL查詢:
select BS.order_id, XYZ.dt_added AS xyz_date,
ABC.dt_added AS abc_date, PQR.dt_added AS pqr_date,
from base_status BS
LEFT JOIN base_status XYZ ON BS.order_id=TAS.order_id and TAS.status='xyz'
LEFT JOIN base_status ABC ON BS.order_id=TAS.order_id and TAS.status='abc'
LEFT JOIN base_status PQR ON BS.order_id=PQR.order_id and PQR.status='pqr'
....
我的問題:如何避免3個左連接。只有一個連接有什麼可做的嗎?