问题出处:http://www.oracle.com.cn/viewthread.php?tid=141615&extra=page%3D10
表A
RIQ SL
20090607 130
20090614 136
表B
RIQ EDATE
20090607 200906061448
20090607 200906062149
20090607 200906041840
20090614 200906121056
20090614 200906142035
20090614 200906122310
20090614 200906081840
希望得到的结果为
RIQ SL EDATE
20090607 130 200906061448
20090607 0 200906062149
20090607 0 200906041840
20090614 136 200906121056
20090614 0 200906142035
20090614 0 200906122310
20090614 0 200906081840
请问查询应该怎么写呢?望高手帮忙
RIQ SL
20090607 130
20090614 136
表B
RIQ EDATE
20090607 200906061448
20090607 200906062149
20090607 200906041840
20090614 200906121056
20090614 200906142035
20090614 200906122310
20090614 200906081840
希望得到的结果为
RIQ SL EDATE
20090607 130 200906061448
20090607 0 200906062149
20090607 0 200906041840
20090614 136 200906121056
20090614 0 200906142035
20090614 0 200906122310
20090614 0 200906081840
请问查询应该怎么写呢?望高手帮忙
- SELECT RIQ,
- DECODE(SL, LAG(SL) OVER(PARTITION BY RIQ ORDER BY RIQ, EDATE), 0, SL) SL,
- EDATE
- FROM (SELECT B.RIQ, A.SL, B.EDATE FROM A, B WHERE A.RIQ = B.RIQ)