I am developing a system using MySQL queries written by another programmer and adapting its code.
I have three questions:
1.
One of the queries has this select statement:
SELECT [...] AVG(mytable.foo, 1) AS 'myaverage'`,
Is 1 in AVG(mytable.foo, 1) AS 'myaverage' legal? I can not find documentation to support its use?
2.
The result of this gives me averages of up to two decimal places, why ?.
3.
I use this to create a temporary table. So:
(SELECT [...] AVG(`mytable`.`foo`, 1) AS `myaverage`, FROM [...] WHERE [...] GROUP BY [...]) UNION (SELECT [...] FROM [...] WHERE [...] GROUP BY [...]) ) AS `tmptable` ORDER BY `tmptable`.`myaverage` DESC
When I sort the table in this column, I get an output that indicates that this average is stored as a row, so the result looks like this:
9.3
11.1
To get around this, what should I use?
Should I use CAST or CONVERT since DECIMAL (which I read is mostly binary) itself BINARY or UNSIGNED?
Or is there a way to indicate that myaverage should be an integer when I call it in an AS statement?
Sort of:
SELECT AVG(myaverage) AS `myaverage`, INT(10)
Thanks.
source share