如何根据NumOfGames%
等每种产品类型计算% = TOTAL/PERPRODUT_TYPE
。
这是我对TOTAL NumOfGames
SELECT
DPT.[Name] [ProductType],
SUM([FinishedGameCycleCount]) [NumOfGames]
FROM [WarehouseMgmt].[FactGameAgr] FWA
JOIN [WarehouseMgmt].[DimPlayer] DPL ON FWA.[PlayerId] = DPL.[Id]
JOIN [WarehouseMgmt].[DimGame] DG ON FWA.[GameId] = DG.[Id]
JOIN [WarehouseMgmt].[DimProductType] DPT ON DPT.Id = FWA.ProductTypeId
WHERE [WarehouseMgmt].[GetDateTimeFromTimeId](TimeId) >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp)), 0)
GROUP BY DPT.[Name]
答案 0 :(得分:1)
使用SUM()OVER()
SELECT
DPT.[Name] [ProductType],
SUM([FinishedGameCycleCount]) [NumOfGames],
SUM([FinishedGameCycleCount]) *100. / SUM(SUM([FinishedGameCycleCount])) OVER() [percentage]
FROM [WarehouseMgmt].[FactGameAgr] FWA
JOIN [WarehouseMgmt].[DimPlayer] DPL ON FWA.[PlayerId] = DPL.[Id]
JOIN [WarehouseMgmt].[DimGame] DG ON FWA.[GameId] = DG.[Id]
JOIN [WarehouseMgmt].[DimProductType] DPT ON DPT.Id = FWA.ProductTypeId
WHERE [WarehouseMgmt].[GetDateTimeFromTimeId](TimeId) >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp)), 0)
GROUP BY DPT.[Name]