我需要显示这些专栏
date(transaksi.tanggaldibuat) income cost
2017-11-15 50000 10000
date cost_production
2017-11-15 30000
2017-11-15 300000
2017-11-14 1
我正在使用此查询..
SELECT table2.date,
format(COALESCE(sum(table1.income-table1.cost),0),0) as cash,
format(coalesce(sum(table2.costproduction),0),0) as totalcost,
(sum(table1.income-table1.cost)- sum(table2.costproduction))as revenue
from table1 left join table2 on date(table1.tanggaldibuat) = table2.date group by table2.date
但这会导致循环值......
date(transaksi.tanggaldibuat) cash totalcost revenue
2017-11-15 80,000 330,000 -250000
2017-11-14 0 1 NULL
date(transaksi.tanggaldibuat) cash totalcost revenue
2017-11-15 40,000 330,000 -290000
2017-11-14 0 1 -1
循环值我的意思是现金应该有40,000而不是80,000。 提前谢谢你!