MySQL Case in Select Statement with LIKE operator

后端 未结 4 1445
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 13:32

Is it possible to combine the CASE statement and the LIKE operator in a MySQL SELECT statement?

For Example, I am trying to query

4条回答
  •  迷失自我
    2021-02-01 13:40

    Perhaps use LEFT()?

    SELECT
        CASE 
          WHEN LEFT(digits, 4) = '6901' THEN substr(digits,4)
          WHEN LEFT(digits, 2) = '91' THEN substr(digits,2)
        END 
    FROM raw
    

    Should be more performant than the LIKE.

提交回复
热议问题