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:
We define an employee's total earnings to be their monthly salary * months worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table. Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings. Then print these values as 2 space-separated integers.
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 Employee table containing employee data for a company is described as follows:
Sample Input:
Solution-1: Using GROUP BY, ORDER BY & LIMIT (MySQL Query):
- '*' operator is used for multiplying Salary & Months.
- Using ORDER BY MAX_SAL DESC, salaries are sorted in descending order of max_salary.
- LIMIT is used to limit the number of rows in the output. LIMIT 1 will return only the first row of the output. (Which will be the maximum salary due to order by desc clause.)
Solution-2: Using GROUP BY & SUB-QUERY (MySQL Query):
NOTE: - '*' operator is used for multiplying Salary & Months.
- SUB-QUERY is used to get results only for maximum salary.
- '*' operator is used for multiplying Salary & Months.
- SUB-QUERY is used to get results only for maximum salary.
Solution-3: Using MAX & SUB-QUERY (MySQL Query):
NOTE: - MAX function used to get the Maximum (Largest) of the values of all the records in the column name passed to the function.
- SUB-QUERY is used to get results only for maximum salary.
- MAX function used to get the Maximum (Largest) of the values of all the records in the column name passed to the function.
- SUB-QUERY is used to get results only for maximum salary.