SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Using SUM in a query

    Every time a user upgrades to the paid membership a new row is inserted into the payments table. A monthly membership is $5.00, however, after fees from paypal, I actually get $4.55. The following query is correctly adding up all of the $5.00 payments but, of course, it's not really the dollar amount I end up with. What is the best way to tweak this query so that it takes $.45 off each payment before adding them all up?

    SELECT sum(amount) as total FROM payments WHERE YEAR(payDate) = YEAR(CURDATE()) AND MONTH(payDate) = MONTH(CURDATE()) and uID in (select uID from users where subscription = 'Silver')

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    SELECT sum(amount - 0.45) as total
    FROM payments 
    WHERE YEAR(payDate) = YEAR(CURDATE()) 
    AND MONTH(payDate) = MONTH(CURDATE()) 
    AND uID IN (SELECT uID FROM users WHERE subscription = 'Silver')


Bookmarks

Posting Permissions

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