参考这个SO问题
有没有办法将基于2个分隔符的列拆分为4列?
如果我有一个包含此数据的列。
11-3-1-4 $72390.00
我将如何制作
col1 col2 col3 col4 col5
11 3 1 4 72390.00
另外我应该保留原始列吗?
答案 0 :(得分:1)
string_to_array()
可用于此:
select c1[1] as col1,
c1[2] as col2,
c1[3] as col3,
c1[4] as col4,
substr(col5, 2) as col5
from (
select string_to_array((string_to_array(the_column, ' '))[1], '-') as c1,
(string_to_array(the_column, ' '))[2] as col5
from the_table
) t