MySQL没有PIVOT功能

MySQL数据透视功能_mysql

 

 

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

 

MySQL数据透视功能_html_02

 

 

 

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

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

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