mysql with 3 group by and sum
Posted
by
cyberfly
on Stack Overflow
See other posts from Stack Overflow
or by cyberfly
Published on 2011-01-06T03:29:25Z
Indexed on
2011/01/06
3:54 UTC
Read the original article
Hit count: 158
mysql
|mysql-query
Hi all
I have this data in my table (tb_cash_transaction)
I want to group the TYPE column, CURRENCY_ID column and AMOUNT column so it will become like below:
**Currency** **Cash IN** **Cash OUT** **Balance**
14 40000 30000 10000
15 50000 40000 10000
Rule :
1.Group by currency
2.Then find the sum of cash in for that currency
3.Find the sum of cash out for that currency
4.Get the balance (sum cash in - sum cash out)
How to achieve it using mysql? I try using group by but cannot get the desired output.
Thanks in advance
© Stack Overflow or respective owner