I don't have the db on this computer but here is what the data looks like.
getting the credits for ticket_id = 100 and draw_id = 4 would yield 3Code:draws ----- 1 10/07/2004 2 17/07/2004 3 24/07/2004 4 31/07/2004 ticket_sales ------------- ID ticket_id draw_id participant_id amount_paid -- --------- ------- -------------- ----------- 1 100 1 5000 5 2 100 2 5000 0 3 100 3 5000 0 4 100 4 5000 2 5 200 1 6000 0 6 200 2 6000 0 7 200 3 6000 0 8 200 4 6000 5
getting the credits for ticket_id = 200 and draw_id = 4 would yield 4
DaPi: I hope the second case helps show why its not sum(payments) - count(tickets). As sum(payments) would be 5 and count(tickets) would be 4 which is 1 and incorrect.




Reply With Quote