AVG() FUNCTION RETURNING DIFFERENT VALUES FOR SAME INPUT

Database
Enthusiast

AVG() FUNCTION RETURNING DIFFERENT VALUES FOR SAME INPUT

HI

   I am using the average function to find the average of column having many rows. Each time i execute the query i get different result sets. The change is very small in precision. Ex. 16.12345678 and 16.12345679. Why do i see this change? Am i making some mistake here or is it something with Teradata? Please help.

Regards

Arun

Tags (1)
3 REPLIES
Junior Contributor

Re: AVG() FUNCTION RETURNING DIFFERENT VALUES FOR SAME INPUT

Hi Arun,

the resulting datatype of an AVG is a FLOAT.

What's the datatype of the base column?

You can rewrite an any AVG(column) using SUM(column) / COUNT(column) which will use the original type (but might have to cast it to a higher number of digits).

Enthusiast

Re: AVG() FUNCTION RETURNING DIFFERENT VALUES FOR SAME INPUT

Thanks. The data type of base column is DECIMAL(38,8) and the resulting data type is also same.

Enthusiast

Re: AVG() FUNCTION RETURNING DIFFERENT VALUES FOR SAME INPUT

Hi Arun,

If you are still facing the issue, can you share the query?