Numeric overflow error for AVG function

Database

Numeric overflow error for AVG function

hello,
we all knew that we may get numeric overflow during count, sum etc... but I see that with MIN, MAX, and AVG functions too... All I am doing is just picking one of the existing values...

I also tried to CASTing to DECIMAL(38,0) and no luck in there...

After doing the above casting, MIN and MAX went well, but not AVG. AVG is anyways between MIN and MAX values and i am surprised that AVG didn't work..

any thoughts please??
2 REPLIES

Re: Numeric overflow error for AVG function

OKIE, to compute average, it should first compute the SUM internally and that's where the issue coming I think... so, I think, the sum is going beyond the container...

Re: Numeric overflow error for AVG function

To get rid of the error use the following format and you should no longer get an error:

AVG( CAST( column_name as DECIMAL(16,0)))