I need to display the code of the Department in the School table with the highest total Salary of any department.
So I tried this:
SELECT MAX(Total), dept
FROM (SELECT SUM(salary) AS Total, dept from school group by dept) AS Temp;
Which gives me the correct result; however it shows the field MAX(Total) and I just want the code of the department to show. What should I change?
You can do
SELECT a.dept FROM (
SELECT MAX(Total), dept
FROM (SELECT SUM(salary) AS Total, dept from school group by dept) AS Temp
) AS a;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With