DBAsupport.com Forums - Powered by vBulletin
Results 1 to 10 of 11

Thread: add and subtract column in query

Threaded View

  1. #4
    Join Date
    Dec 2003
    Posts
    90
    I don't have the db on this computer but here is what the data looks like.

    Code:
    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 = 100 and draw_id = 4 would yield 3
    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.
    Last edited by luciffer; 07-06-2004 at 01:14 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width