在Db2中使用没有ROW_NUMBER()和OVER()函数的预准备语句

时间:2010-09-30 06:00:44

标签: sql db2 prepared-statement

假设我有一张桌子T_SWA。这是我准备好的陈述。

Select version 
From (Select id, version, creator, 
       created_date ROW_NUMBER() OVER(order by created_date) cnt 
    From T_SWA 
    Where cnt=3 and id=35); 

我需要从T_SWA表中选择第3个最新版本。任何人都可以在不使用ROW_NUM()OVER()功能的情况下建议替换此查询吗?

1 个答案:

答案 0 :(得分:0)

首先取三个最近,然后从这三个拿第一个。

select id, version, creator, created_date 
from (
    select id, version, creator, created_date 
        from T_SWA
        where id = 35
        order by created_date desc
        fetch first 3 rows only
)
order by created_date
fetch first 1 row only;