Please make use of my blog posts for learning purpose only and feel free to ask your questions in the comment box below in case of any doubt.
Click Here for the previous blog-post in the series.
Recommended SQL Courses:
SQL Problem Statement:
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 (i.e.: actual - miscalculated average monthly salaries), and round it up to the next integer.
Input Format:
The EMPLOYEES table is described as follows:
Table: EMPLOYEES Columns |
Note: Salary is measured in dollars per month and its value is 10^5.
Sample Input:
Solution: Using MAX & MIN Function (MySQL Query):
- AVG function used to get the average of the values of all the records in the specified column name passed to the function.
- CEIL function used to get the nearest integer of the original number passed to the function. (The output will be always greater than or equal to the original number).
Eg. CEIL(2.34) will return 3 - REPLACE function is used to replace all occurrences of the substring within an input string with another substring. Here, '0' is replaced with a blank ('') character.