有一个像这样的表:
name ZK04_COUNT ZK05_COUNT ZK04_PRICE ZK05_PRICE
A 15 0 150.00 0
A 0 20 0 223.00
B 11 0 75.00 0
B 0 24 0 250.00
我试图将它转换为这样的格式:
name ZK04_COUNT ZK05_COUNT ZK04_PRICE ZK05_PRICE
A 15 20 150.00 223.00
B 11 24 75.00 250.00
我的代码如下:
这是我的代码:
SELECT *
FROM (
SELECT
r.name
,r.AUART
, CASE WHEN r.AUART = 'ZK05' THEN count(r.MATNR) ELSE '' END AS ZK05_COUNT
, CASE WHEN r.AUART = 'ZK04' THEN count(r.MATNR) ELSE '' END AS ZK04_COUNT
, CONVERT(money, sum(CAST(netpr as MONEY)), 1) as ToplamTutar
FROM GARANTI_YP_RAPORU as r
group by r.name ,r.AUART
) as gTablo
PIVOT
(
SUM(ToplamTutar)
FOR gTablo.AUART IN ([ZK05],[ZK04])
)
AS p1
我希望输出在单行中显示。如何做到这一点?