IT分销/经销数据库

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

表1acctno           bal         trandate --------------------------------------------102012011        81.23       2010-01-03102012...显示全部
表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

查看其它 20 个回答leo_wyn的回答

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_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
浏览723

回答者

leo_wyn
商业智能工程师Security

leo_wyn 最近回答过的问题

回答状态

  • 发布时间:2010-07-14
  • 关注会员:0 人
  • 回答浏览:723
  • X社区推广