美文网首页
Redshift 字符串Split

Redshift 字符串Split

作者: 流浪山人 | 来源:发表于2019-05-10 18:19 被阅读0次

    create table ewen_testsplit
    (name varchar(25) null,
    id varchar(255) null
    )

    ;
    create table numbers
    (
    id int
    )
    ;
    insert into numbers
    select 1
    union all
    select 2
    union all
    select 3
    union all
    select 4
    union all
    select 5
    union all
    select 6
    union all
    select 7
    union all
    select 8
    union all
    select 9
    union all
    select 10
    union all
    select 11
    union all
    select 12
    union all
    select 13
    union all
    select 14
    union all
    select 15

    insert into ewen_testsplit values
    ('ewen','1,2,3,4')

    select * from ewen_testsplit

    select name, SPLIT_PART(id,',',1) from ewen_testsplit
    select name, SPLIT_PART(id,',',2) from ewen_testsplit
    select name, SPLIT_PART(id,',',3) from ewen_testsplit
    select name, SPLIT_PART(id,',',4) from ewen_testsplit
    select name, SPLIT_PART(id,',',5) from ewen_testsplit

    select name, SPLIT_PART(s.id,',',n.id) ,regexp_count(s.id, ',')
    from ewen_testsplit s inner join numbers n on n.id<regexp_count(s.id, ',')+2

    相关文章

      网友评论

          本文标题:Redshift 字符串Split

          本文链接:https://www.haomeiwen.com/subject/vihzoqtx.html