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

若如初见. 提交于 2019-12-01 11:00:31

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!