将垂直行转换为水平行的问题
SELECT
rate.`customer_rate_id`,
rate.`customer_name`,
rate.`destination_name`,
del.`wh_storage_location_name`,
(CASE WHEN rate.destination_name=1 THEN 'zone a' ELSE 'zone s' END) ZONE_A,
(CASE WHEN rate.destination_name=2 THEN 'zone b' ELSE 'zone d' END) ZONE_B
FROM `m_ac_customer_rate` rate
LEFT JOIN m_point_delivery_location del ON del.`wh_storage_location_id`=rate.`destination_name`
WHERE
`customer_name`=7
GROUP BY rate.`destination_name`
我得到的结果是
zone_name weight rate
zone A 1.5 kg 100 Rs
zone B 2 kg 150 R
s
但我想要
weight zone A zone B
1.5 kg 100 Rs , 150 Rs
2 kg 150 Rs , 200 Rs