mysql 行列转换

转换前 
SELECT  name, order_id FROM wine_s_beaut_order_item  WHERE order_id = '4028801c6531f05a01653208c002000f'  blog

转换后it

SELECT  order_id,
MAX(CASE types WHEN 'beau_cork' THEN `name` ELSE 0 END) AS 'beau_cork',
MAX(CASE types WHEN 'beau_bottle' THEN `name` ELSE 0 END) AS 'beau_bottle',
MAX(CASE types WHEN 'beau_time' THEN `name` ELSE 0 END) AS 'beau_time' 
FROM wine_s_beaut_order_item    GROUP BY order_idim

 

相关文章
相关标签/搜索