Topic: Count of debts under the written out accounts
Something I rested and I do not understand where further to move, like absolutely simple request (
There is a table ` sht ` - accounts, and ` pp ` - payment orders. Under each account which is in operation, there can be some payment orders, or any.
It is necessary to select accounts behind which the debt is registered, i.e. the total of the account is more than total of the pay-sheets which have arrived on this account.
SELECT SELECT sht.sht_no, client, status, sht_sum, SUM (pp.pl_sum) FROM sht RIGHT JOIN pp USING (sht_no) WHERE SHT.status> 0 # here simply means that the account "in operation" GROUP BY pp.sht_no # here like as the grouping for operation SUM but if in the table pp still there are no pay-sheets under these accounts it turns out they is necessary fall out HAVING SHT.sht_sum> SUM (pp.pl_sum)
Deduces only those accounts on which there is at least one payment.
How to deduce as well on what there is no pay-sheet?