quintroo
quintroo

Reputation: 75

Merge rows with same column value into 1 - Oracle

I have an Oracle table looking like this:

+--+--+------+
|DB|NR|Amount|
+--+--+------+
|BE|10|20    |
+--+--+------+
|BE|10|30    |
+--+--+------+
|FR|20|50    |
+--+--+------+
|FR|20|10    |
+--+--+------+
|DE|30|25    |
+--+--+------+
|BE|35|75    |
+--+--+------+

Which query do I need to use to merge all the rows with the same DB and NR?

This should be the result:

+--+--+------+
|DB|NR|Amount|
+--+--+------+
|BE|10|50    |
+--+--+------+
|FR|20|60    |
+--+--+------+
|DE|30|25    |
+--+--+------+
|BE|35|75    |
+--+--+------+

Thx in advance.

Upvotes: 1

Views: 5347

Answers (2)

vhadalgi
vhadalgi

Reputation: 7189

try this

select DB,NR,sum(amount) from table group by NR,DB

Upvotes: 4

Ahmadhc
Ahmadhc

Reputation: 173

Try this :

  select DB,NR, SUM(Amount) 
    from table
    group by DB,NR

Upvotes: 3

Related Questions