如何在表格中获得第n个最高值... [英] How do I get the nth highest value in a table...
本文介绍了如何在表格中获得第n个最高值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张包含20条记录的表格,我想选择排名前5位的最高薪水,而不是前5行或第5条记录。
我尝试了什么:
i尝试了一些问题,但我没有得到预期的结果,所以请提前帮助我。
i have a table with 20 records in it, i want to select the top 5th highest salary in it not top 5 rows or 5th record.
What I have tried:
i have tried some quires but i didn't got the desired results so please help me thank you in advance.
推荐答案
如果你想找到班上最高的5个人,你怎么做?
1.首先,对它们进行排序通过将它们从最高到最短(或反之亦然)排列;
2.接下来,开始计算并选择前面的前5个人。
在SQL中执行相同操作,
A.使用 ORDER BY [ ^ ]按照感兴趣的字段对表格进行排序,例如工资。
B.接下来,通过查看 SQL SELECT了解如何获得前5行TOP,LIMIT,ROWNUM [ ^ ],有不同的版本。
将A和B放在一个SQL语句中,这将是您正在寻找的答案。
If you want to find the top 5 tallest guys in a class, how do you do it?
1. First, sort them up by lining them from the tallest to the shortest (or vice versa);
2. Next, start to count and select the first 5 guys in front.
Do the same in SQL,
A. Use ORDER BY[^] to sort the table by the field of interest, e.g. salary.
B. Next, find out how to get the top 5 rows by checking out SQL SELECT TOP, LIMIT, ROWNUM[^], there are different versions.
Putting A and B in one SQL statement and that will be the answer you are looking for.
在MySQL中的
in MySQL
> SELECT * FROM table ORDER BY hits DESC limit 5;
Oralce的
in Oralce
> SELECT * FROM table ORDER BY hits DESC where rownum <5;
这篇关于如何在表格中获得第n个最高值...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文