MySQl透视动态数据

时间:2016-10-24 21:52:38

标签: mysql pivot mariadb

我需要一些帮助尝试在MYSQL中获取以下输出。 鉴于我有权创建临时表 如何使用 MySQL 语法

输出以下行

这是sql

中数据的抽样
            Create table #Temp
            ( Category varchar(20)
            ,CreatedMonth int
            ,NumberOfIssues int
            )
            Insert into  #Temp
            SELECT 'Access  Support',9,28
            UNION ALL
            SELECT 'Ecom  Support',9,76
            UNION ALL
            SELECT 'Inhouse ',9,7
            UNION ALL
            SELECT 'Access  Support',10,59
            UNION ALL
            SELECT 'Server Support',10,23

我想要的MySQL中的Resulset是 类别Month_9 Month_10

            The first row having the values of [Access  Support],28,59
            The second row having the values of [Ecom  Support],76,0
            The third row having the values of [Inhouse ],7,0
            The fourth row having the values of [Server Support],0,23

至少定义了30个类别。

感谢您的任何建议。 SD

1 个答案:

答案 0 :(得分:0)

使用GROUP_CONCAT

SELECT Category, GROUP_CONCAT(NumberOfIssues) FROM yourtable WHERE CreatedMonth BETWEEN 9 AND 10 GROUP BY Category