postgresql 如何在PostgreSQL的where子句中写rownum
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9288648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to write rownum in where clause in PostgreSQL
提问by Amrin
I am quite new to Postgres database. I have one query:
我对 Postgres 数据库很陌生。我有一个查询:
select offer_id, offer_date
from CMS_OFFER
where ROWNUM < 300
which executes in Oracle but in Postgres it is not excuted. I tried with row_number() also. It is not able to execute. Please help me: how I can achieve this?
它在 Oracle 中执行,但在 Postgres 中不执行。我也试过 row_number() 。它无法执行。请帮助我:我怎样才能做到这一点?
回答by Thilo
While not exactly the same as Oracle's ROWNUM, Postgresql has LIMIT:
虽然与 Oracle 的 ROWNUM 不完全相同,但 Postgresql 有 LIMIT:
select offer_id,offer_date from CMS_OFFER LIMIT 299
The difference is that ROWNUM is applied before sorting, and LIMIT after sorting (which is usually what you want anyway).
不同之处在于 ROWNUM 在排序前应用,LIMIT 在排序后应用(这通常是您想要的)。
回答by Andrey Frolov
select offer_id,offer_date from CMS_OFFER limit 299