Ashish B Sathish
Ashish B Sathish

Reputation: 121

SQL code to sum duplicate rows and also retain the duplicate rows

How to write a sql query

A        1    
B        1    
C        1    
A        1    
A        1    
B        1    
B        1    
C        1    
B        1

to make it look like

A      3
B      4
C      2
A      3
A      3
B      4
B      4
C      2
B      4

Upvotes: 0

Views: 29

Answers (1)

a1ex07
a1ex07

Reputation: 37382

SELECT field1, SUM(field2) OVER (PARTITION BY field1) as total
FROM table1

More info about window/analytic functions in Oracle : http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions004.htm

Upvotes: 2

Related Questions