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
|
2139 Discussions
|
Please Login in order to post a comment
SELECT CAST( CEILING( AVG(CAST(salary AS FLOAT)) - AVG(CAST(REPLACE(CAST(salary AS VARCHAR(20)), '0', '') AS FLOAT)) ) AS INT ) FROM employees;
SELECT ceil(avg(Salary) - avg(replace(salary,'0',''))) from EMPLOYEES;
in sql server, I needed multiple casting
SELECT Ceiling(AVG(salary-REPLACE(salary, '0', ''))) from EMPLOYEES;
Calculate the differences first, and then apply the avg, and then ceilling
select ceil(avg(salary) - avg(replace(salary,'0',''))) from employees
here if we use round it will round the number to nearest whole number, that's why we use ceil. so it will round the element to nearest integer.