简体   繁体   中英

sql oracle sum group

The SQL I coded gives me the following output:

column1  column2    column3

50       RedCar     8
50       RedCar     8
50       RedCar     8
40       BlueCar    8
20       YellowCar  8
80       WhiteCar   8
50       RedCar     8

The final result I am looking for is:

column1  column2      column3

50       RedCar       32
40       BlueCar      8
20       YellowCar    8
80       Whitecar     8 

What should happen in text:

My SQL finds all rows with the same ID in column1 and makes one row from it summing up the numbers in column3 .

Try to use group by clause with sum function as below

select column1,column2,sum(column3) as column3
from tab
group by column1,column2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM