salary<\/td> | Integer<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n where employee_id<\/em> is an employee’s ID number, name<\/em> is their name, months<\/em> is the total number of months they’ve been working for the company, and salary<\/em> is the their monthly salary.<\/p>\n\n\n\nSample Input <\/strong><\/p>\n\n\n\nemployee_id<\/th> | name<\/th> | months<\/th> | salary<\/th><\/tr><\/thead> |
---|
12228<\/td> | Rose<\/td> | 15<\/td> | 1968<\/td><\/tr> | 33645<\/td> | Angela<\/td> | 1<\/td> | 3443<\/td><\/tr> | 45692<\/td> | Frank<\/td> | 17<\/td> | 1608<\/td><\/tr> | 56118<\/td> | Patrick<\/td> | 7<\/td> | 1345<\/td><\/tr> | 59725<\/td> | Lisa<\/td> | 11<\/td> | 2330<\/td><\/tr> | 74197<\/td> | Kimberly<\/td> | 16<\/td> | 4372<\/td><\/tr> | 78454<\/td> | Bonnie<\/td> | 8<\/td> | 1771<\/td><\/tr> | 83565<\/td> | Michael<\/td> | 6<\/td> | 2017<\/td><\/tr> | 98607<\/td> | Todd<\/td> | 5<\/td> | 3396<\/td><\/tr> | 99989<\/td> | Joe<\/td> | 9<\/td> | 3573<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n Sample Output<\/strong><\/p>\n\n\n\n69952 1<\/code><\/pre>\n\n\n\n<\/span>Explanation<\/strong><\/span><\/h2>\n\n\n\nThe table and earnings data is depicted in the following diagram:<\/p>\n\n\n\nemployee_id<\/th> | name<\/th> | months<\/th> | salary<\/th> | earnings<\/th><\/tr><\/thead> |
---|
12228<\/td> | Rose<\/td> | 15<\/td> | 1968<\/td> | 29520<\/td><\/tr> | 33645<\/td> | Angela<\/td> | 1<\/td> | 3443<\/td> | 3443<\/td><\/tr> | 45692<\/td> | Frank<\/td> | 17<\/td> | 1608<\/td> | 27336<\/td><\/tr> | 56118<\/td> | Patrick<\/td> | 7<\/td> | 1345<\/td> | 9415<\/td><\/tr> | 59725<\/td> | Lisa<\/td> | 11<\/td> | 2330<\/td> | 25630<\/td><\/tr> | 74197<\/td> | Kimberly<\/td> | 16<\/td> | 4372<\/td> | 69952<\/td><\/tr> | 78454<\/td> | Bonnie<\/td> | 8<\/td> | 1771<\/td> | 14168<\/td><\/tr> | 83565<\/td> | Michael<\/td> | 6<\/td> | 2017<\/td> | 12102<\/td><\/tr> | 98607<\/td> | Todd<\/td> | 5<\/td> | 3396<\/td> | 16980<\/td><\/tr> | 99989<\/td> | Joe<\/td> | 9<\/td> | 3573<\/td> | 32157<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n The maximum earnings<\/em> value is 69952<\/strong>. The only employee with earnings<\/em>=69952<\/strong> is Kimberly<\/em>, so we print the maximum earnings<\/em> value (69952<\/strong>) and a count of the number of employees who have earned $69952<\/strong> (which is 1<\/strong>) as two space-separated values.<\/p>\n\n\n\n<\/span>Solution – Top Earners in SQL<\/strong><\/span><\/h2>\n\n\n\n<\/span>MySQL<\/strong><\/span><\/h3>\n\n\n\nselect max(months * salary), count(months * salary) \nfrom Employee where (months * salary) \n= (select max(months * salary) from Employee);<\/pre>\n\n\n\n |
|
|