May 17, 2022 at 3:51 am
Hi All,
I have an input like below.
mytable:
id | name | no
--------------
1 | A | 10
1 | A | 20
1 | A | 40
2 | B | 20
2 | B | 20
1 | C | 20
1 | C | 23
3 | D | 15
3 | D | 15
Need the output like below, how to achieve this , Sum of no based on id, name needs to result in Sumdat
for eg
id=1 and name =A and no we have 10+20+40=70 = Sumdat column
id=3 and name =D and no we have 15+15=30 = Sumdat column
mytable:
id | name | no | SumDat
----------------------
1 | A | 10 | 70
1 | A | 20 | 70
1 | A | 40 | 70
2 | B | 20 | 40
2 | B | 20 | 40
1 | C | 20 | 43
1 | C | 23 | 43
3 | D | 15 | 30
3 | D | 15 | 30
Thanks !
May 17, 2022 at 4:23 am
select id
,name
,no
,sum(no) OVER(PARTITION BY id, name)
from mytable
I want to be the very best
Like no one ever was
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply