S.Patil S.Patil - 1 year ago 71
MySQL Question

sql query to sum of same id but different value?

sql query to sum of same id but different value??....
I am trying to calculate sum of same id...following is my table

id barter_value
2 50,000
2 1,50,000
3 47,000
3 55,000
3 50,00,000

I want output like

id barter_value
2 2,00,000
3 51,00,2000

select a.buyer_id,
from add_to_cart as a
join(select buyer_id,
sum(prod_barter_val) as total
from add_to_cart group by buyer_id) as b
on a.buyer_id = b.buyer_id;

Answer Source

You can just do like:

select buyer_id, sum(prod_barter_val) from add_to_cart group by buyer_id

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download