SQL AVG returning an int

CodeKingPlusPlus picture CodeKingPlusPlus · Jun 19, 2012 · Viewed 32.1k times · Source

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.

Answer

Simon Dorociak picture Simon Dorociak · Jun 19, 2012

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.