Reputation: 145
Good day, I have a table as follows.
What I would love to do is add a new Column that will tabulate/summarize (anyway possible) called "New Net" by CovID/PolicyNo/CovYear/Positive(Negative) values.
In the example below the new column would look like this. In short, what we are trying to do is SumUp all the Values in that group and only place that total in the first row of that group and zero out all the others. Any help/pointers would be appreciated with this. I have tried SQL Server Window Functions, standard SUM/GROUP.
Upvotes: 0
Views: 943
Reputation: 668
This should meet ypur expectations:
SELECT PolicyNo ,
CovID ,
CovYear ,
p ,
net,
CASE WHEN ROW_NUMBER()OVER(PARTITION BY CovID, PolicyNo, CovYear, net ORDER BY PolicyNo) = 1 THEN net ELSE 0 END AS NewNet
FROM dbo.test1;
Upvotes: 1