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
|
2143 Discussions
|
Please Login in order to post a comment
SELECT CEIL(AVG(CAST(Salary AS DOUBLE)) - AVG(CAST(REPLACE(CAST(Salary AS CHAR),'0','') AS DOUBLE))); FROM EMPLOYEES; ??? Why it's wrong
SELECT CAST ( CEILING ( AVG (CAST ( SALARY AS FLOAT ) ) - AVG( CAST( REPLACE( CAST( SALARY AS VARCHAR(20) ),'0', '') AS FLOAT )) ) AS INT ) FROM EMPLOYEES;
This works...
with raw AS ( select avg(Salary) as actual ,avg(cast(replace(Salary,'0','') as SIGNED)) as mis_calculated from EMPLOYEES )
select ceil(actual - mis_calculated) from raw
SELECT CEIL(AVG(Salary) - AVG(CAST(REPLACE(CAST(SALARY AS CHAR),'0','') AS UNSIGNED))) FROM EMPLOYEES;
SELECT CAST( CEILING( AVG(CAST(salary AS FLOAT)) - AVG(CAST(REPLACE(CAST(salary AS VARCHAR(20)), '0', '') AS FLOAT)) ) AS INT ) FROM employees;