截取字符串一般用 substring 就够用了。对于有些长度不定的就没法用这个函数了,但还是有规律的,可以某个字符分割。
这时需要 split_part 函数,如:
-- url 一共3个 - ,字符串被分成4部分,取最后一部分,那最后一个参数就是4
select split_part(fs.cdn_url ,'-', 4) from file_store fs
如果 分割符 数量不一样怎么办,这里就要计算分割符的数量了
select count(*) 户数,concat(a1,'/',LEFT(a2,5)) as aa from (
select
remark3,
position('\21' in remark3),
SPLIT_PART(remark3, '\', 5) ::text AS a1,SPLIT_PART(remark3, '\', 6) ::text AS a2
from dcy_survey where remark3<>'' ) as ff group by aa order by aa
标签:aa,Postgresql,text,截取,remark3,PART,字符串 From: https://www.cnblogs.com/Fooo/p/17750828.html