将Access TRANSFORM / PIVOT查询转换为SQL Server

时间:2019-07-05 14:09:24

标签: sql pivot transform

我正在尝试将以下SQL查询从Access转换为SQL Server查询。 SQL Server不支持转换功能。

查询:

TRANSFORM Count(ID_Data.ID_Number_SEA) AS Breakers
SELECT 1980+SubString([ID_Data].[ID_Number_SEA],7,2) AS [Year], +SubString([ID_Data].[ID_Number_SEA],9,2) AS [Month]
FROM ID_Data LEFT JOIN ProductionOrder ON ID_Data.Production_Order = ProductionOrder.ProductionOrder
WHERE (((ProductionOrder.Main_PO)='E170:LV_SECT' Or (ProductionOrder.Main_PO)='E170:SB_SECT' Or (ProductionOrder.Main_PO)='E220:SB_SECT' Or (ProductionOrder.Main_PO)='E230:SB_SECT' Or (ProductionOrder.Main_PO)='E290:MC_SHPS' Or (ProductionOrder.Main_PO)='E290:SB_SECT' Or (ProductionOrder.Main_PO)='OEM' Or (ProductionOrder.Main_PO)='SIE-CANADA' Or (ProductionOrder.Main_PO)='E250:BWSEN_S' Or  (ProductionOrder.Main_PO)='E250:BWSEN_C' Or (ProductionOrder.Main_PO)='E250:SB_SECT' Or (ProductionOrder.Main_PO)='E250:BWSEN_X'))
GROUP BY 1980+SubString([ID_Data].[ID_Number_SEA],7,2), +SubString([ID_Data].[ID_Number_SEA],9,2)
ORDER BY 1980+SubString([ID_Data].[ID_Number_SEA],7,2) DESC , +SubString([ID_Data].[ID_Number_SEA],9,2) DESC
PIVOT dbo_ProductionOrder.Main_PO;

0 个答案:

没有答案