2013年(350)
分类: Mysql/postgreSQL
2013-04-25 10:35:41
接上~~
并不困难,只要对我们的稍加改动即可
JSSWEB> select ad1,nav from(
2 select c.*,row_number() over(partition by ad1 order by ad2) rn from (
3 select a.adddate ad1,
4 a.addvalue av1,
5 b.adddate ad2,
6 b.addvalue av2,
7 case
8 when a.addvalue != 0 then
9 a.addvalue
10 when a.addvalue = 0 and b.adddate > a.adddate then
11 b.addvalue
12 when a.addvalue = 0 and b.adddate is null then
13 first_value(b.addvalue) over(order by b.adddate desc nulls last)
14 else
15 0
16 end nav
17 from tmp4 a, tmp4 b
18 where b.addvalue(+) != 0
19 and b.adddate(+)>a.adddate
20 order by 1
21 ) c where nav!=0)where rn=1
22 ;
AD1 NAV
-------------------- ----------
2007-03-01 3.64
2007-03-02 3.64
2007-03-05 3.64
2007-03-06 3.82
2007-03-07 3.47
2007-03-08 3.47
2007-03-09 4.01
2007-03-12 4.01
2007-03-13 4.01
2007-03-14 4.21
2007-03-15 4.12
2007-03-16 4.12
2007-03-17 4.12
怎么样,亲自动手试试吧~~
==================================
查看前三例: