有人可以帮我在mssql中编写这段代码吗?我在mssql中读取了关于动态透视的多个答案,但是不能将它应用于我的特定代码,因为我不知道如何在一个标题中连接多个聚合。
以下是Access中的代码:
TRANSFORM SUM(Sales.Tons) AS SumOfTonsSELECT Sales.ID_SaleDest
FROM (QualPack
INNER JOIN (Groups
INNER JOIN (Customers
INNER JOIN SaleDest
ON Customers.ID_Customer = SaleDest.ID_Customer)
ON Groups.ID_Group = SaleDest.ID_Group)
ON QualPack.ID_QualPack = SaleDest.ID_QualPack)
INNER JOIN Sales
ON SaleDest.ID_SaleDest = Sales.ID_SaleDest
WHERE (((
Year([Date_shipped]))=2017)
AND ((
SaleDest.ID_Group)<>10)
AND ((
QualPack.Quality_Second)<>'NO')
AND ((
Sales.ID_Dataset)="AC"
OR (
Sales.ID_Dataset)="BU"))
OR (((
Year([Date_shipped]))=2016)
AND ((
SaleDest.ID_Group)<>10)
AND ((
QualPack.Quality_Second)<>'NO')
AND ((
Sales.ID_Dataset)='AC'))
GROUP BY Sales.ID_SaleDest,
SaleDest.ID_Group
ORDER BY Sales.ID_SaleDest,
[Sales]![ID_Dataset] & '-' & Year([Sales]![Date_shipped]) & '-M' & Format(Month([Sales]![Date_shipped]),'00') PIVOT [Sales]![ID_Dataset] & '-' & YEAR([Sales]![Date_shipped]) & '-M' & Format(MONTH([Sales]![Date_shipped]),'00') WITH OWNERACCESS OPTION;
问题在于:
PIVOT [Sales]![ID_Dataset] & '-' & YEAR([Sales]![Date_shipped]) & '-M' & Format(MONTH([Sales]![Date_shipped]),'00')
如何在mssql中进行透视?
赞赏你的帮助。
玛雅