My webserver is running MySQL client version 5.1.56.
My devserver is running MySQL client version 5.0.7.
This query gives me the same result on both servers:
SELECT scenario_user_ratings.userid,
AVG(scenario_user_ratings.rating)
FROM scenario_user_ratings
GROUP BY scenario_user_ratings.userid
both report result:
userid AVG(scenario_user_ratings.rating)
1 3.3659
21 2.8000
22 3.2069
but this query yields different results
SELECT * FROM ( SELECT scenario_user_ratings.userid,
AVG(scenario_user_ratings.rating)
FROM scenario_user_ratings
GROUP BY scenario_user_ratings.userid) tabl
WHERE tabl.userid < 5
Dev MySQL v5.0.7 result
userid AVG(scenario_user_ratings.rating)
1 0.9999 <-- average values are always this, regardless
Web MySQL v5.1.56 result
userid AVG(scenario_user_ratings.rating)
1 3.3659 <-- correct
Apart from the obvious comment of dev environment should always match production can someone please explain to me how putting the original query into another query is nuking my AVG() values to 0.99999 ? I’ve narrowed it down to that particular action, and only for this local version of MySQL.
Thank you.
see
hereif you encounter the same problem, you can simply replace the AVG function by the combination
SUM/COUNT.For example, the following query: