We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- SQL
- Aggregation
- The Blunder
- Discussions
The Blunder
The Blunder
Sort by
recency
|
2105 Discussions
|
Please Login in order to post a comment
SELECT CEIL(AVG(SALARY) - AVG(REPLACE(SALARY, '0', ''))) FROM EMPLOYEES;
how to tackle the problem can any one briefly expline it!.
That's it
SELECT CEIL(AVG(salary) - AVG(REPLACE(salary,0,""))) FROM Employees;
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.
SELECT CEILING( ABS( AVG(1.0 * Salary) - AVG(1.0 * CAST(REPLACE(Salary, '0', '') AS INT)) ) ) AS error_amount FROM Employees;