gpt4 book ai didi

MySQl 透视动态数据

转载 作者:行者123 更新时间:2023-11-29 20:09:25 25 4
gpt4 key购买 nike

我需要一些帮助来尝试在 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 中想要的结果集是类别 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 个类别。

感谢您的任何建议。标清

最佳答案

使用GROUP_CONCAT

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

关于MySQl 透视动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40228126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com