SQL AVG returning an int SQL AVG returning an int sql sql

SQL AVG returning an int


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.

enter image description here

For example, if you want your result to be float, you need to ensure your column or expression type is float.