I want to calculate the sum of the same ids and display in each record. expected Sample is given below
I want to calculate the sum of the same ids and display in each record. expected Sample is given below
Use analytics SUM():
SELECT
Code, SUM(Value) OVER (PARTITION BY Code) as Value
FROM mytable;
Summing over the window should allow you to maintain the overall sum for each record. ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ensures that all values are taken into consideration
SELECT
Code,
SUM(Value) OVER (PARTITION BY Code ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
FROM
mytable;