IT分销/经销数据库

能用sql实现吗?请求db2高人得帮助

表1
acctno           bal         trandate
--------------------------------------------
102012011        81.23       2010-01-03
102012011       100.21       2010-01-05
102012011       481.23       2010-02-04
102012011      1300.21       2010-04-05
102012011       281.23       2010-04-07
102012011      1020.21       2010-05-01
102012011       821.23       2010-05-21
102012011       100.21       2010-05-26
表二
acctno           bal                trandate       trandate2
------------------------------------------------------
102012011        81.23       2010-01-03     2010-01-05
102012011       100.21       2010-01-05     2010-02-04
102012011       481.23       2010-02-04     2010-04-05
102012011      1300.21       2010-04-05     2010-04-07
102012011       281.23       2010-04-07     2010-05-01
102012011      1020.21       2010-05-01     2010-05-21
102012011       821.23       2010-05-21     2010-05-26
102012011       100.21       2010-05-26     2012-12-31

表一到表二的变换能用sql实现吗,如何解决这个问题请求db2高人的指导
参与21

21同行回答

leo_wynleo_wyn商业智能工程师Security
db2 v9 以后的版本才支持olap函数 :)显示全部
db2 v9 以后的版本才支持olap函数 :)收起
系统集成 · 2010-07-14
浏览699
leo_wynleo_wyn商业智能工程师Security
给你个olap 函数参考:select accto, bal, trandate,coalesce(min(trandate) over  (partition by accto order by to_date(trandate, 'YYYY-MM-DD HH24:MI:SS') nulls last rows between 1 following and 1 following),'2010-12-31 00:00:00') next_trandatefr...显示全部
给你个olap 函数参考:

select accto, bal, trandate,

coalesce(

min(trandate) over
  (partition by accto order by to_date(trandate, 'YYYY-MM-DD HH24:MI:SS') nulls last rows between 1 following and 1 following),

'2010-12-31 00:00:00'

) next_trandate


from table(values
        (102012011, 81.23,  '2010-01-03 00:00:00'),
        (102012011, 100.21, '2010-01-05 00:00:00'),
        (102012011, 481.23, '2010-02-04 00:00:00')
              
)

as t(accto, bal, trandate)收起
系统集成 · 2010-07-14
浏览724
leo_wynleo_wyn商业智能工程师Security
可以使用olap 函数,  partiton by acctno order by trandate  rows between current row and 1 following显示全部
可以使用olap 函数,  partiton by acctno order by trandate  rows between current row and 1 following收起
系统集成 · 2010-07-09
浏览386
leo_wynleo_wyn商业智能工程师Security
实际lz的意思是按照acctno分组, 然后按照trandate  进行排序后再首尾相接trandate显示全部
实际lz的意思是按照acctno分组, 然后按照trandate  进行排序后再首尾相接trandate收起
系统集成 · 2010-07-09
浏览416

    提问者

    zihowe
    系统工程师bank
    擅长领域: 数据库

    相关问题

    相关资料

    相关文章

    问题状态

  • 发布时间:2010-07-09
  • 关注会员:0 人
  • 问题浏览:11871
  • 最近回答:2010-08-28
  • X社区推广