The Blunder

  • + 0 comments

    select cast(ceil(avg(cast(salary as decimal)) - avg(cast(replace(cast(salary as varchar(20)),'0','') as decimal))) as int) from employees; This will work for sure in DB2. Had to cry a lot over it. Till the end only because of rounding off trouble.

    Here, we typecast the integer salary to string in order to remove zeroes. Later we convert it into decimal for average substraction for clear rounding off. Finally we type cast into integer. Hope this helps.