将一个带逗号的字符串拆分为列



例如,我有下表:

| Block                       |
| abcdefgh,12kjkjkj,231wewoxyz|

如何将其转换为:

| Block1   | Block2   | Block3     |
| abcdefgh | 12kjkjkj | 231wewoxyz |

注意:

  • 每个"块"最多有 8 个逗号(因此可以分成 9 个较小的块(。逗号的数量各不相同;有些有 8 个逗号,有些有 4 个逗号,有些有 7 个逗号,依此类推。每个较小的块将占据一列。

我使用普雷斯托,顺便说一句。

在我看来,您只需使用split_part函数来创建列,如下所示:

SELECT
split_part(Block, ',', 1) AS Block1,
split_part(Block, ',', 2) AS Block2,
split_part(Block, ',', 3) AS Block3,
split_part(Block, ',', 4) AS Block4,
split_part(Block, ',', 5) AS Block5,
split_part(Block, ',', 6) AS Block6,
split_part(Block, ',', 7) AS Block7,
split_part(Block, ',', 8) AS Block8,
split_part(Block, ',', 9) AS Block9
FROM
your_table

相关内容

  • 没有找到相关文章

最新更新