I have a problem with SUMs. In my table I have tens of Hs and ABs fields associated with playerID field. I need to get SUM of Hs divided by SUM of ABs and order the results by the derived number. When I use the below query it shows SUM.
This returns me SUM of all the H associated by playerID. But when I change the code to below one, it does not give me SUM.Code:SELECT SUM(H) , SUM(AB) , playerID FROM mytable WHERE yearID = 2005 GROUP BY playerID LIMIT 10
H and AB fields are both integers. I hope I was able to clearly explain what my problem is.Code:SELECT SUM(H) , SUM(AB) , SUM(H)/SUM(AB) HAB , playerID FROM mytable WHERE yearID = 2005 GROUP BY playerID ORDER BY HAB DESC LIMIT 10
Thanks in advance.