在库克服务器中,我正设法获得5名最高工资。
我的薪水一样。
5000
5000
4500
4500
3000
2000
1000
500
400
和我一样
5000
5000
4500
4500
3000
2000
1000
在库克服务器中,我正设法获得5名最高工资。
我的薪水一样。
5000
5000
4500
4500
3000
2000
1000
500
400
和我一样
5000
5000
4500
4500
3000
2000
1000
如果你想获得五位最高的单独薪金(无论数额多少倍可能显示),你需要使用<条码> DENSE_RANK(的排名职能和一个计算中心来做到这一点:
DECLARE @salaries TABLE (salary DECIMAL(18,4))
INSERT INTO @salaries VALUES(5000)
INSERT INTO @salaries VALUES(5000)
INSERT INTO @salaries VALUES(4500)
INSERT INTO @salaries VALUES(4500)
INSERT INTO @salaries VALUES(3000)
INSERT INTO @salaries VALUES(2000)
INSERT INTO @salaries VALUES(1000)
INSERT INTO @salaries VALUES(500)
INSERT INTO @salaries VALUES(400)
;WITH SalariesRanked AS
(
SELECT
Salary,
SalaryNumber = DENSE_RANK() OVER(ORDER BY Salary DESC)
FROM
@salaries
)
SELECT salary
FROM SalariesRanked
WHERE SalaryNumber <= 5
结果是产生了这样的产出:
salary
5000.0000
5000.0000
4500.0000
4500.0000
3000.0000
2000.0000
1000.0000
SELECT TOP 5 salary FROM your_table
ORDER BY salary DESC
select salary
from
(
select salary,
dense_rank() over(order by salary desc) as rn
from YourTable
) as T
where rn <= 5
Try on SE-Data
SELECT TOP 5 Salary
FROM [Table]
GROUP BY Salary
ORDER BY Salary DESC
你们需要把问题分类,以避免重复的工资。
I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...
In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
Is it possible to use the sqlcmd command to dump table structure the way it can be done with mysqldump?
Hi I have the following SP, however when I use LINQ to SQL it generates 2 multiple recordsets. For my sanity I am trying to fathom out what it is in the stored procedure that is doing this and would ...
I want to create a table in MS SQL Server 2005 to record details of certain system operations. As you can see from the table design below, every column apart from Details is is non nullable. CREATE ...
I love the new DATE datatype in SQL Server 2008, but when I compare a DATE field to a DATETIME field on a linked server (SQL 2005, in this case), like this: DECLARE @MyDate DATE SET @MyDate = CONVERT(...
How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8