Concatenate Multiple Row Values into 1 Row, with SQL for iSeries

后端 未结 1 1092
慢半拍i
慢半拍i 2021-01-15 17:08

First, I need to thank Kent Milligan and his article at http://www.mcpressonline.com/sql/techtip-combining-multiple-row-values-into-a-single-row-with-sql-in-db2-for-i.html f

相关标签:
1条回答
  • 2021-01-15 17:32

    I think you just need to integrate type at the correct points thoughtout the query.

    without being able to test, I think this would be close; but I may have missed something...

    WITH numbered_sets(make, type, model, curr, prev) AS (
       SELECT make, type, model,
           ROW_NUMBER() OVER (PARTITION BY make, Type ORDER BY Make, Type, model) AS curr,
           ROW_NUMBER() OVER (PARTITION BY make, type ORDER BY Make, type, model) -1 AS prev
       FROM inventory)
    SELECT make, Type
           MAX (TRIM(L ',' FROM
                 CAST(SYS_CONNECT_BY_PATH(model, ',') AS VARCHAR(256)) ))
    FROM numbered_sets
    START WITH curr = 1
    CONNECT BY make = PRIOR make AND prev = PRIOR curr and type = prior type
    GROUP BY make, type
    

    Perhaps we need do change the connect by to do a concat before connect by... though I can't see why this would help yet...

    CONNECT BY concat(make,type) = PRIOR concat(make,type) AND prev = PRIOR curr
    
    0 讨论(0)
提交回复
热议问题