【问题标题】:how to get latest 'n' updated row from a table [duplicate]如何从表中获取最新的'n'更新行[重复]
【发布时间】:2012-10-18 16:12:14
【问题描述】:
【问题讨论】:
标签:
sql
oracle
oracle10g
top-n
【解决方案1】:
您可以在 Oracle 中使用 ROWNUM。点击Here 获取文档
select *
from
( select *
from your_table
where cust_id=<given cust_id>
order by lastUpdatedDate desc )
where ROWNUM <= 10;
【解决方案2】:
Oracle 支持 ROW_NUMBER() 和窗口函数。试试下面的,
SELECT act_id, cust_id, lastUpdatedDate, custActivity
FROM
(
SELECT act_id, cust_id, lastUpdatedDate, custActivity,
ROW_NUMBER() OVER (PARTITION BY cust_id ORDER BY lastUpdatedDate DESC) rn
FROM tableNAME
) x
WHERE rn <= 10
【解决方案3】:
希望这对你有帮助-
select act_id,cust_id,lastUpdatedDate,custActivity
from (
select act_id,cust_id,lastUpdatedDate,custActivity, row_number() over (order by lastUpdatedDate) r
from abc
where act_id=<cust_id>
)
where r between 1 and 10;