I want to calculate a delta between the rows of two tables with the exact same structure, but not necessarily the same data.
table 1 (predictions)
Id | Name | GP | G | A
table 1 (actual data)
Id | Name | GP | G | A
result (matched by Id):
Id | (GP1-GP2) AS DeltaGP | (G1-G2) AS DeltaG | (A1-A2) AS DeltaA |
Catch my drift? This is to caclulate the error of a prediction model in SSAS
Here is my code:
SELECT P.[Player_id]
,P.[PlayerName]
,sum(P.[Games Played])-sum(S.[GamesPlayed]) AS GP
,sum(P.[Total Goals])-sum(s.[TotalGoals]) AS Goals
,sum(P.[Total Assists])-sum(s.[TotalAssists]) AS Assists
FROM [PredictionsPlayersHistory] as P
JOIN [V_StatsPlayers] AS S on p.pLAYER_id = s.Player_id
where S.LastPlayedDate >= '2010-02-01' and P.Player_id
= 8471675 group by P.[Player_id],P.[PlayerName]
order by Goals desc, Assists desc, GP asc
problem is the results arent right:
Predictions (SUM)
PlayerName GP Goals Assists
Sidney Crosby 56 28 34
Actual data (SUM)
PlayerName GP Goals Assists
Sidney Crosby 26 17 24
Results
Sidney Crosby 28 -42 -98