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
|
1736 Discussions
|
Please Login in order to post a comment
MS SQL Server
SELECT CEILING(AVG(CAST(Salary as decimal)) - AVG(CAST(REPLACE(Salary, '0', '') as decimal))) FROM EMPLOYEES;
MySQL
SELECT CEIL(AVG(salary) - AVG(REPLACE(salary, '0', ''))) FROM employees;
SELECT CEILING(AVG(SALARY) - AVG(CAST(REPLACE(SALARY, '0', '') AS DECIMAL))) FROM EMPLOYEES;
This query is completing correct and it is giving exact output in local db. still i'm getting errors in this question.
SELECT CEILING(ABS( (SELECT AVG(SALARY) FROM EMPLOYEES) - (SELECT AVG(CAST(REPLACE(CAST(SALARY AS CHAR), '0', '') AS SIGNED)) FROM EMPLOYEES) )) AS error;
Cast is used to convert into integer again and ceiling is used to round up to next integer. abs is used to calculate absolute difference
select ceil(avg(salary)-avg(replace(salary,0,""))) from employees;