SQL查询从表中获取前两个最高的列值 [英] SQL Query to get first two highest column values from a table

查看:60
本文介绍了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

您将对其他任何列执行相同的操作,只需替换SELECTORDER BY部分中的列名即可.

You would do the same for any other columns, just replace the column name in the SELECT and in the ORDER BY sections.

这篇关于SQL查询从表中获取前两个最高的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆