2016-07-21 44 views

回答

0

一個簡短的回答你短的問題是:

SELECT salary 
FROM employees 
ORDER BY salary DESC 
FETCH FIRST 2 ROWS ONLY 
+0

我認爲這隻適用於Oracle 12c – vercelli

+0

@Vercelli是正確的。他的答案是ANSI標準,不僅適用於較早的Oracles,而且還適用於SQL Server等競爭對手。 – Unoembre

+1

這也是ANSI標準SQL @john,並且可用於[PostgreSQL](https://www.postgresql.org/docs/current/static/sql-select.html),[DB2]( https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/sqlref/src/tpc/db2z_sql_fetchfirstclause.html)和[SQL Server](https://msdn.microsoft.com/zh-cn/library/ ms188385.aspx),以及Oracle和其他人。 – Ben

0
select empid, salary, rn 
from (
    select empid, salary , rank() over(order by salary desc) as rn 
    from emp) t 
where rn<=2; 
相關問題