I have an Access database for testing which contains two tables, tbvendite and tbpagamenti. Into tbvendite I put every sell concerning the customers, specifying date, Idcliente, cliente, id operation and operation and the amount. Into tbpagamenti I write all payments made by customers that could be the sum of amount grouped by day of sell.
Conditions are that customer can buy in a day but he could not pay, so that he could pay previous suspended amount without making purchases. I should want extract a report for a customer (or a long report) but the query I thought about using does not produce the result I was hoping for.
SELECT tbvendite.data, tbvendite.idcliente, tbvendite.cliente,
Sum(iif(tbvendite.importo is null,0,tbvendite.importo)) AS amount,
Nz(SS.importo,0) AS PAY
FROM tbvendite
INNER JOIN (SELECT tbpagamenti.idcliente,
Sum(IIf(tbpagamenti.importo Is Null,0,tbpagamenti.importo)) AS Pay
FROM tbpagamenti
GROUP BY tbpagamenti.idcliente) AS SS
ON tbvendite.idcliente = SS.idCliente
GROUP BY tbvendite.data, tbvendite.idcliente, tbvendite.cliente;
tbvendite
tbpagamenti
current results