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
Post a Comment