SQL Select Top

数据表: Employees

EmployeeId FirstName LastName Department Salary
203 Mary Fox Finance 78000
204 Joe Lanyon Finance 45800
205 Sally Daff Finance 57000
206 Grace Salter Finance 62000
302 James Band Development 75000
303 Dona Earl Development 55000
304 Tony Oakes Development 49000

SQL Server

选择前10行数据:

SELECT TOP 10 *
FROM Employees

选择最高工资的前5个数据:

SELECT TOP 5 *
FROM Employees
ORDER BY Salary DESC

选择最高工资的前5%的数据:

SELECT TOP 5 PERCENT *
FROM Employees
ORDER BY Salary DESC
MySQL

选择最高工资的前10行数据:

SELECT *
FROM Employees
ORDER BY Salary DESC
LIMIT 10
Oracle

选择第一行记录:

SELECT *
FROM Employees
WHERE ROWNUM <= 1

选择最高工资的前100行记录:

SELECT *
FROM
  (
     SELECT * 
     FROM Employees
     ORDER BY Salary DESC
  )
WHERE ROWNUM <= 100