Help with SUM SQL Query Please

Discussion in 'MySQL' started by T0PS3O, Jan 5, 2006.

  1. #1
    Table looks like this:

    id | order_id | price_ex | tax

    Example:

    1 | 1000 | 22 | 17.5
    2 | 1000 | 40 | 17.5
    3 | 1004 | 10 | 0.0

    I was hoping to query for order_id 1000 and get the total price inc tax.

    That's (22 * 1.175) + (40 * 1.175).

    But this query doesn't work:

    SELECT SUM(price * (1 + tax)) FROM table WHERE order_id = '1000'

    That gives me a huge amount. So it's probably all wrong. It's on MySQL 3.2 so no sub queries.

    Is there a way to retrieve the total in one go?
     
    T0PS3O, Jan 5, 2006 IP
  2. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why won't you put all data in variables and then calculate with those?
     
    discoverclips, Jan 5, 2006 IP
  3. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #3
    tax is in percentages, so divide it by 100 first

    SELECT SUM(price * (1 + (tax/100) ) ) FROM table WHERE order_id = '1000'
     
    frankm, Jan 5, 2006 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Crikey, I'm getting dumber by the day. Last week I rang Telewest because my broadband modem kept staying in stand by. Turned out there was a stand by button depressed. Now I add 1 + the damn tax which makes it 18.5 times the price. No wonder!

    I nominate this thread for the crappiest of the day. Sorry!
     
    T0PS3O, Jan 5, 2006 IP
  5. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #5
    it happens:) don't get depressed.
     
    legend2, Jan 6, 2006 IP
  6. PhilosopherStone

    PhilosopherStone Guest

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Do you need a group by using maybe a sum() function???
     
    PhilosopherStone, Jan 19, 2006 IP
  7. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Dude, it's already solved.
     
    T0PS3O, Jan 20, 2006 IP