【问题标题】:Return text at the end of a string - Presto SQL返回字符串末尾的文本 - Presto SQL
【发布时间】:2019-03-26 17:06:32
【问题描述】:

我正在尝试返回字符串末尾的文本。

Example #1- ad | aff | 11_32_32_Desired - Text
Example #2- ad | aff | 11_32_32_Desired Text

这是我的专栏中的两种变体,有时所需文本的长度会在我的数据中发生变化。我正在尝试将 Desired Text 值放入它们自己的列中。有些行有 - 而有些则没有。

谢谢!

【问题讨论】:

  • 请显示您想要的结果。并清楚列的内容是什么。

标签: sql amazon-athena presto


【解决方案1】:

Presto SQL 支持regular expressions,试试:

SELECT regexp_extract(column, 'Example #(\d+)\- ad \| aff \| \d\d_\d\d_\d\d_(.*)', 2)
FROM table

【讨论】:

    【解决方案2】:

    如果您想要的是最后一次出现_ 之后的字符串部分,那么:

    select substr(col, length(col) - strpos(reverse(col), '_') + 2)
    

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多