SQL查询从表中获取前两个最高的列值
问题描述:
我想在我的sql中有一个查询,该查询将以-
I want to have a query in my sql which will return the result as -
我有一个名为employee的表,其列名为name,salary,address. 该查询应返回employee表中的前两个最高列值.
I am having a table named employee with columns name,salary,address. The query should return the first two highest column values from the employee table.
这应该是单个查询.
答
如果最高的列是salary
,请执行以下操作:
If the highest column is salary
, you do this:
select salary from employee
order by salary desc
limit 2
您将对其他任何列执行相同的操作,只需替换SELECT
和ORDER BY
部分中的列名即可.
You would do the same for any other columns, just replace the column name in the SELECT
and in the ORDER BY
sections.