zoukankan      html  css  js  c++  java
  • SQL transformation


    SQL transformation

    how can we convert single row to multiple row (example)

    SAP_SALES_ORD_NUM COVERAGE_TERM
    1122 3
     
    I need result as
     
    SAP_SALES_ORD_NUM COVERAGE_TERM
    1122 1
    1122 2
    1122 3



    with temp as(
    select 1122 as SAP_SALES_ORD_NUM , 3 COVERAGE_TERM from sysibm.sysdummy1 ),
    loops (SAP_SALES_ORD_NUM ,COVERAGE_TERM)  as(
    select SAP_SALES_ORD_NUM ,COVERAGE_TERM from temp 
    union all
    select l.SAP_SALES_ORD_NUM ,case when l.COVERAGE_TERM > 1 then l.COVERAGE_TERM - 1 end as COVERAGE_TERM from loops l  ,temp t where t.SAP_SALES_ORD_NUM = l.SAP_SALES_ORD_NUM and l.COVERAGE_TERM >=1 
    )
    select * from loops where COVERAGE_TERM is not null 

     SAP_SALES_ORD_NUM     COVERAGE_TERM
     -----------------     -------------
                  1122                3
                  1122                2
                  1122                1

  • 相关阅读:
    架构师之路
    责任链设计模式
    Junit框架分析
    线程详解
    课程总结
    IO流
    Java第四次作业
    Character string
    实训
    实训SI
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501261.html
Copyright © 2011-2022 走看看