How to avoid round of functionality in AVG() ?

Database

How to avoid round of functionality in AVG() ?

How to find avg based on Floating Number column ?

exmaple:

SELECT empno, AVG(ARPU_AMT) from table group by empno;

I need to get float average, without round the value.
3 REPLIES
Enthusiast

Re: How to avoid round of functionality in AVG() ?

Hi Udhaya,

I joined recently and was going thru the old posts then came accross ur post.

You can avoid the round of functionality in Avg() by casting the value to decimal type

Example: Sel empno,cast(avg(sal) as decimal(7,2)) from emp group by empno
Junior Contributor

Re: How to avoid round of functionality in AVG() ?

The result of that AVG is already a float, so there's not need for a Typecast, this is probably just a display problem:
You probably run that query in SQL Assistant and this defaults to 2 fractional digits for float.
If you right click on the result column there's a "Decimal Places" or modify
Tools -> Options -> Answer Set -> Number of Decimal Places Displayed for Float Columns

Dieter

Re: How to avoid round of functionality in AVG() ?

Yes, It’s SQL Assistant format issue only. Thanks for your information