sqlcastingfloating-pointaverage

SQL AVG returning an int


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.


Solution

  • 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.