The Blunder

Sort by

recency

|

2120 Discussions

|

  • + 1 comment

    Like me, you may keep getting 2252 as the wrong answer (in DB2)

    The solution is to use DECIMAL to perform the calculation using floats and then use INT on the total. You will then get the correct answer 2253.

    SELECT INT(CEIL( AVG(DECIMAL(salary)) - AVG(DECIMAL(replace(char(salary), '0', ''))) )) FROM employees;

  • + 0 comments

    For MySQL Platform

    SELECT CEIL(AVG(salary) - AVG(REPLACE(salary, "0", ""))) FROM employees;
    
  • + 0 comments

    -- MS SQL Server --

    SELECT CAST(CEILING(ABS( AVG(CAST(salary AS FLOAT)) - AVG(CAST( CASE WHEN REPLACE(CAST(salary AS VARCHAR(20)), '0', '') = '' THEN '0' ELSE REPLACE(CAST(salary AS VARCHAR(20)), '0', '') END AS FLOAT) ) )) AS INT) AS Error FROM employees;

  • [deleted]
    + 0 comments

    For MySQL Platform

    SELECT CEIL(AVG(salary) - AVG(REPLACE(salary, "0", ""))) FROM employees;
    
  • + 0 comments
    SELECT ceil(AVG(Salary)- AVG( REPLACE(salary,"0","")))
    FROM EMPLOYEES;