Posts The Blunder
Post
Cancel

The Blunder

The Blunder

  • URL : https://www.hackerrank.com/challenges/the-blunder/problem
  • 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 zeroes removed), and the actual average salary. Write a query calculating the amount of error, and round it up to the next integer.
  • MySQL Solution
1
2
select round(avg(salary)) - round(avg(replace(salary, 0, '')))
from EMPLOYEES;
This post is licensed under CC BY 4.0 by the author.