MySQL没有PIVOT功能

 

 

SELECT userid,

    MAX(CASE WHEN `type` = 1 THEN itemcount END) AS type_1,

    MAX(CASE WHEN `type` = 2 THEN itemcount END) AS type_2,

    MAX(CASE WHEN `type` = 3  THEN itemcount END) AS type_3,

    MAX(CASE WHEN `type` = 4 THEN itemcount END) AS type_4

FROM count_paper_1

GROUP BY userid

ORDER BY userid DESC

 

 

 

 

http://www.cppcns.com/shujuku/mysql/267968.html

https://www.jianshu.com/p/7befd2eb5e88

https://www.5axxw.com/questions/content/rjvex8

 

查看原文