The Blunder

Sort by

recency

|

2124 Discussions

|

  • + 0 comments

    SELECT CEILING( AVG(salary) - AVG(CAST(REPLACE(salary, '0', '') AS UNSIGNED)) ) AS error FROM employees;

  • + 0 comments

    SELECT CAST( CEILING(AVG(CAST(salary AS FLOAT)) - AVG(CAST(REPLACE(CAST(salary AS VARCHAR(21)), '0', '') AS FLOAT))) AS INT) FROM Employees;

  • + 0 comments
    CEILING(
            AVG(CAST(SALARY AS DECIMAL(10,2))) 
            - 
            AVG(CAST(
                    REPLACE(CAST(SALARY AS VARCHAR(20)), '0', '') AS DECIMAL(10,2)
                    )
                )
           )
    FROM EMPLOYEES;
    
  • + 0 comments

    In SQL Server: Question is to round up to the "next integer". Hence, we used CEILING( ) function.

    SELECT CAST(CEILING(AVG(CAST(salary AS FLOAT)) - AVG(CAST(REPLACE(CAST(salary AS VARCHAR(21)), '0', '') AS FLOAT))) AS INT) FROM Employees;

  • + 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;