mysql - Joining two table with SUM of Column and Group by another column -
need join , group sum() function 2 tables.
the tables under:
debit table credit table --------------------- --------------------- customername debit customername credit --------------------- --------------------- customer1 200.00 customer1 100.00 customer1 300.00 customer1 100.00 customer2 100.00 customer1 100.00 customer2 600.00 customer2 200.00 ----------------------- customer2 300.00 customer2 50.00 -----------------------
i need show 2 join table as:
join table(debit credit table) ------------------------------------------ customername debit credit closing ------------------------------------------ customer1 500.00 300.00 200.00 customer2 700.00 550.00 150.00 ------------------------------------------
this far getting doesn't yield right result:
"select debit_tbl.customername, sum(debit_tbl.debit) debit, sum(credit_tbl.credit) credit, sum(debit_tbl.debit) - sum(credit_tbl.credit) closing debit_tbl left outer join credit_tbl on debit_tbl.customername = credit_tbl.customername group debit_tbl.debit union select debit_tbl.customername, sum(debit_tbl.debit) debit, sum(credit_tbl.credit) credit, sum(debit_tbl.debit) - sum(credit_tbl.credit) closing debit right outer join credit_tbl on debit_tbl.customername = credit_tbl.customername group debit_tbl.debit" -------------------------------------------
this should work:
select customername, debit, credit, debit-credit closing (select d.customername customername, sum(d.debit) debit, sum(c.credit) credit debit d inner join credit c on d.customername = c.customername )
Comments
Post a Comment