what is this sql query?

Discussion in 'MySQL' started by promotingspace.net, Sep 16, 2009.

  1. #1
    Hi
    I cannot figure out this query:
    SELECT symbol,SUM(IF(t_type='sell',-shares,shares)) AS shares,
                                                               MAX(price) AS maxprice, MIN(price) AS minprice
                                                               FROM transactions
                                                              WHERE completed=0
                                                              GROUP BY symbol
                                                              ORDER BY shares
    Code (markup):
    My problem is "-shares"; what does it mean?
    how about this: IF(t_type='sell',-shares,shares)
    t_type and shares are table fields
    Thanks for your help
     
    promotingspace.net, Sep 16, 2009 IP
  2. Traffic-Bug

    Traffic-Bug Active Member

    Messages:
    1,866
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #2
    - shares means it is adding negative count, so the "shares" column will show correct figure.
     
    Traffic-Bug, Sep 16, 2009 IP
  3. Lavee

    Lavee Well-Known Member

    Messages:
    234
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #3
    SUM(IF(t_type='sell',-shares,shares)) AS shares

    gives you the total number of shares held after subtracting all the sales for that stock symbol

    Thanks

    Lavee
     
    Lavee, Sep 16, 2009 IP