Mysql : left outer join issue -
i have 2 tables :
income(month, amount)
expenditure(month, amount)
i need display each month of table income amount minus expenditure amount (if exists).
think need use left outer join between 2 tables, like
select income.amount - expenditure.amount income left outer join expenditure on income.month = expenditure.month but don't know how http://sqlfiddle.com/#!9/7a7d5/1
if can on sqlfiddle
thanks.
i assume if there no income should treated 0, likewise expenditure.
mysql doesn't have full outer join can similar:
select month, sum(amount) (select month, income amount income union select month, - expenditure amount expenditure) group month; this creates union of 2 tables (with expenditure negative simplicity). sums amounts , groups month.
example: http://sqlfiddle.com/#!9/7a7d5/14
Comments
Post a Comment