In one of my queries it appears that the AVG
function is returning an int.
select ..., AVG(e.employee_level)avg_level
How do I get it to return floating point values? I tried casting it but all my rows for avg_level
were still integers.
In one of my queries it appears that the AVG
function is returning an int.
select ..., AVG(e.employee_level)avg_level
How do I get it to return floating point values? I tried casting it but all my rows for avg_level
were still integers.
Try to do it like this:
AVG(Cast(e.employee_level as Float)) as avg_level
Also i found this topic where you can find some another approach but i not used its and don't know exactly whether works or not.
Casting is more certain, but ...AVG(1.0 * e.employee_level)...
might do it as well, and can be more legible.
The returned type of the AVG
depends on the evaluated type of the expression passed to the function.
For example, if you want your result to be float
, you need to ensure your column or expression type is float
.
AVG(Cast(e.employee_level as DECIMAL(10,O))
THIS WILL WORK IN MYSQL YOU ARE CATING THE ANS TO GIVE THE VALUE UPTO 0 DECIMALS SO THIS WILL WORK SUPPOSE THE ANS IS 945.454 SO AVG(Cast(e.employee_level as DECIMAL(10,O)) WILL GIVE 945 AND AVG(Cast(e.employee_level as DECIMAL(10,1)) WILL GIVE 945.5 HOPE YOU GOT THE ANS