简体   繁体   中英

SUM column values based on two rows in the same tables in SQL

I have one table like below in my SQL server.

Trans_id    br_code bill_no amount
1           22      111     10
2           22      111     20
3           22      111     30
4           22      111     40
5           22      111     10
6           23      112     20
7           23      112     20
8           23      112     20
9           23      112     30

and I want desired output like below table

s.no    br_code  bill_no    amount
1       22       111        110
2       23       112        90

try this:

select br_code, bill_no, sum(amount)
from TABLE
group by br_code, bill_no

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