例子:
id core primary secondary
101 4355|6755 4355|7866
102 8566|6755 8566 8566
```````````````````````````````````````````````````````````````````````````````
I need to split the data into another table. One with only codes and indicators. All the codes should be in one column under codes and their respective codes as an indicator in other columns as below:
``````````````````````````````````````````````````````````````````````````
id codes core_ind primary_ind secondary_ind
101 4355 Y Y
101 6755 Y
101 7866 Y
102 8566 Y Y Y
102 6755 Y
我可以使用横向拆分列,但不确定如何将指标放在各自的列中。你能提出什么建议吗?以下是我用于拆分的代码。使用此代码,我可以将所有代码和 ID 放在各自的列下。现在,我需要把我上面提到的指标
SELECT id, c.value::varchar AS codes
FROM table
,lateral flatten (input => split(core, '|')) c
UNION ALL
SELECT id, d.value::varchar AS codes
FROM table
,lateral flatten (input => split(primary, '|')) d
UNION ALL
SELECT id, e.value::varchar AS codes
FROM table
,lateral flatten (input => split(secondary, '|')) e
提前致谢!!