【问题标题】:I am trying to break down break 1 column down into multiple columns我正在尝试将 1 列分解为多列
【发布时间】:2020-11-02 10:49:38
【问题描述】:

我正在编写 mySQL 视图

当前列示例是;

001 London (UK)
002 Manchester (UK)
003 New York (USA)

我正在尝试在单独的列中显示;

001 UK
002 UK
003 USA

基本上去掉城市和括号

【问题讨论】:

    标签: mysql sql string split


    【解决方案1】:

    一个选项使用字符串函数:

    select 
        substring_index(col, ' ', 1) val1,
        substring(substring_index(col, ')', 1), locate('(', col) + 1) val2
    from t
    

    Demo on DB Fiddle

    【讨论】:

      【解决方案2】:

      你也可以使用正则表达式:

      select regexp_replace(col, '^.*[()]([^)]*)[)]$', '$1')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-07
        • 2018-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-15
        • 2022-06-28
        相关资源
        最近更新 更多