MySQL: How do I list one column and sum the other? -


i'm using following sql:

  select     a.name accountname,     sum((i.value - i.paidvalue)) onemonth   insertions   join contracts c on i.contractid = c.id   join accounts on c.accountid = a.id   i.value > i.paidvalue     , i.isdeleted false     , i.iscanceled false     , i.month = 8     , i.year = 2013 

it should produce output this:

accountname | onemonth companya    | 3000 [ sum of 1000, 1000, 1000 ] companyb    | 1000 

but it's doing is:

accountname | onemonth companya    | 4000  

what doing wrong?

you forgot group clause

group a.id 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -