-4

真的有办法做到这一点吗?我在最近的一次采访中被问到这个问题,但是当我有机会提问时,我忘记了向面试官询问解决方案。

我已经尝试了所有可能的方法来做到这一点,但似乎无法在不使用子查询的情况下找到方法。我需要同时显示姓名和薪水,而不仅仅是薪水。

4

3 回答 3

3

You might order the whole table by salary descending, and fetch only the first row. Doesn't strike me as a very clever interview question, though.

于 2012-09-20T19:01:28.073 回答
1

If you're in MySQL, you can use limit :

select *
from employee
order by salaray desc
limit 0,1

I don't think there's a way to do it without subquery if limit isn't implemented (like in oracle)

于 2012-09-20T19:00:43.763 回答
0

试试这个例子(假设薪水不可为空)

SELECT a.*
FROM employee a
LEFT JOIN employee b
ON b.salary > a.salary
WHERE b.salary IS NULL;
于 2012-09-21T16:38:22.557 回答