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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. SQL
  3. Aggregation
  4. The Blunder
  5. Discussions

The Blunder

Problem
Submissions
Leaderboard
Discussions

Sort 1151 Discussions, By:

recency

Please Login in order to post a comment

  • nhipham117
    4 days ago+ 1 comment

    MySQL

    SELECT CEILING(AVG(SALARY) - AVG(REPLACE(SALARY,'0','')))
    FROM EMPLOYEES
    
    0|
    Permalink
  • anatolju
    5 days ago+ 1 comment

    SQL Server The problem here is that AVG() returns an integer when used on integers. So the result will be wrong. You have to convert the values to float before using AVG(). This worked for me:

    select
        cast(ceiling(avg(cast(salary as float)) - avg(cast(replace(convert(varchar(5), salary), "0", "") as float))) as int)
    from employees
    
    -1|
    Permalink
  • dhakshna17
    5 days ago+ 0 comments

    SELECT CEILING ((AVG (salary)) - AVG (REPLACE (salary,0,""))) AS avg_sal FROM EMPLOYEES

    0|
    Permalink
  • dhakshna17
    5 days ago+ 0 comments

    SELECT CEILING ((AVG (salary)) - AVG (REPLACE (salary,0,""))) AS avg_sal FROM EMPLOYEES

    0|
    Permalink
  • tranhoxuanthanh1
    6 days ago+ 0 comments

    MS SQL SEVER: - Salary : INT => AVG Salary: INT > FLOAT - REPLACE (salary,0,""): VARCHAR > FLOAT - CEILING: FLOAT => NUMERIC OR INT

    SELECT CAST (CEILING (AVG (CAST (salary AS FLOAT)) - AVG (CAST(REPLACE (salary,0,"") AS FLOAT))) AS NUMERIC) FROM EMPLOYEES

    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy