一、GP或PostgreSQL
1.字段拆分成行
unnest(string_to_array(test, ','))
例如某一字段值为"a,b,c,d",使用string_to_array将其拆分为数组,然后使用unnest将数组平铺成一张表
SELECT unnest(string_to_array('555,666,777', ','))
2.字段拆分成列
根据某个符号拆分:
SELECT
split_part(aaa,'~', 1) AS c1,
split_part(aaa,'~', 2) AS c2,
split_part(aaa,'~', 3) AS c3
from (
SELECT 'a~04~666' AS aaa
) AS temp;
2.字段合并
string_agg(test, ',')
将几行数据按照某字段合并成字符串