[英]Select the row with maximum value for a column MySQL
我有一個名為“ employee”的表,我需要獲得薪水最高的行,並且該雇員來自“ New York”。
select * from employee where city = 'New York' and MAX(salary);
似乎無法正常工作,請給我建議一種方法
嘗試這個::
select
*
from employee
where city = 'New York'
order by Salary desc limit 1
這是簡單的方法。 您還可以使用分組方式,然后子查詢
select * from employee where city = 'New York' order by Salary desc limit 1
這樣,您將從紐約獲得最高薪水的所有雇員。 IE,如果您有另一名員工的salary = 2000
,您也將獲得它。
SELECT * FROM employee WHERE city = 'New York' AND salary = MAX(salary);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.