select D.name as Department, E.name as Employee, max(salary) as Salary from Employee E , Department D where E.DepartmentId = D.Id group by D.id
I tried to use something like this, but it did not pass. When two departments has the same max salary, it only outputs one row.
However, this is not how it works in my local mysql.
Why is this wrong?
I think in this case max() only gives the max salary of the group. So a subquery is required to build a table of the max salary in each group and then find every employee who has the max salary in the department.
Aggregate functions, which max() is one off, work in conjunction with group by. Typically. So this puzzles me as well.
I get the same issue.
I test this in other online environment and it works, not sure why it shows error here...
I write like
what's wrong with it ? why must write department_id ?
when I write like in the bracket, it shows the max salary in each group. but when I add it to the whole sentence it does not work.
Pls check out my solution without subquery, max function and follow-up questions:)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.