Hacker Rank SQL

The Blunder Solution

Hello Friends in this article i am gone to share Hacker Rank SQL Solutions with you | The Blunder Solution

Also Visit:ย  Population Density Difference Solution



Samantha was tasked with calculating the average monthly salaries for all employees in theย EMPLOYEESย table, but did not realize her keyboardโ€™sย 0ย key was broken until after completing the calculation. She wants your help finding the difference between her miscalculation (using salaries with any zeros removed), and the actual average salary.

Write a query calculating the amount of error (i.e.ย actual โ€“ miscalculated:ย ย average monthly salaries), and round it up to the next integer.

Input Format

Theย EMPLOYEESย table is described as follows:

Column Type
ID Integer
Name String
Salary Integer

Note:ย Salaryย is per month.


  • 1000 < Salary < 10^5

Sample Input

Id Name Salary
1 Kristeen 1420
2 Ashley 2006
3 Julia 2210
4 Maria 3000

Sample Output



The table below shows the salariesย without zerosย as they were entered by Samantha:

Id Name Salary
1 Kristeen 142
2 Ashley 26
3 Julia 221
4 Maria 3

Samantha computes an average salary ofย 98.00. Theย actualย average salary isย 2159.00.

The resulting error between the two calculations isย 2159.00 โ€“ 98.00 = 2061.00. Since it is equal to the integerย 2061, it does not get rounded up.


Solution โ€“ The Blunder

MySQL Code
SELECT CEIL(AVG(Salary)-AVG(REPLACE(Salary,'0','')))



Disclaimer: The above Problems are generated by Hacker Rank but the Solutions are Provided by NYANDER.COM. All Hacker Rank SQL Solutions Shared only for Educational and Learning Purpose.