【问题标题】:Need to get data from Presto Teradata with restricting column data需要通过限制列数据从 Presto Teradata 获取数据
【发布时间】:2018-12-13 18:35:06
【问题描述】:
select * from rest where url like 'https://%.sureshchitturi.com:444/%/%';

我可以使用上面的 where 获取数据,但我想在 select 语句中使用一些东西来获取所有数据,直到第四个 '/' 符号其余不需要建议我使用一些函数来使其工作

sample

Articles/Search/ArtMID/2681/ArticleID/2218/Diet.aspx
OurStory/boot/food/street/MeettheFoodieandtheMD.aspx
TheFood/OurMenu.aspx/abc/def/abbac

output

Articles/Search/ArtMID/2681
OurStory/boot/food/street
TheFood/OurMenu.aspx/abc/def

谢谢

【问题讨论】:

    标签: sql teradata


    【解决方案1】:

    如果总是至少有四个斜线可以使用

    Substr(col, 1, Instr(col, '/', 1, 4)-1)
    

    否则切换到正则表达式:

    RegExp_Substr(col, '(.*?/){3}([^/]+)') -- at least .../.../.../.
    

    【讨论】:

      【解决方案2】:

      请在下面执行:

        SELECT RegExp_Substr('Articles/Search/ArtMID/2681/ArticleID/2218/Diet.aspx', '(.*?/){3}([^/]+)')  
          FROM dual;
      

      【讨论】:

      • Teradata 中没有 dual 表,否则它是我的正则表达式的精确副本。
      猜你喜欢
      • 2014-04-25
      • 1970-01-01
      • 2020-01-14
      • 2013-11-18
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多