MySQL Forums
Forum List  »  Newbie

Sum column based on criteria on another column
Posted by: Vemsom Helst
Date: December 19, 2016 02:31AM

Hello,
I want to sum the values in column A for distinct numbers in column B.
Example

1 100
2 50
4 50
1 20
1 80
4 40

Requested look:
1 100 200
2 50 50
4 50 90
1 20 200
1 80 200
4 40 90
Or:
1 200
2 50
4 90

I have tried with a few different queries:
- select distinct matnr, sum(KWMENG) from VBAP_0101 group by MATNR
- select KWMENG from( select distinct matnr, sum(KWMENG) from VBAP_0101 group by MATNR)

Preferably I want to have the first requested table and I thought I could do it easiest with a subquery but my query on't stick. Any ideas?

Thanks!

Options: ReplyQuote


Subject
Written By
Posted
Sum column based on criteria on another column
December 19, 2016 02:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.