【问题标题】:Multiple conditions (equal & like ) on the same column with conditions in another column SQL Server同一列上的多个条件(equal 和 like)与另一列 SQL Server 中的条件
【发布时间】:2019-06-06 02:24:54
【问题描述】:

问题是如何将like 或“相等”条件放在一列中,并将其他条件混合在不同列中

我的目标:

select *
from TABLE
where A_column like 'A%' 
  and B_column = '5' 
  and C_column like 'SH%' or = 'SY_0005'    -- like & equal in one column

我不能通过这样做来使用REGEX_LIKE

select *
from TABLE
where A_column like 'A%' 
  and B_column = '5' 
  and REGEXP_LIKE(C_column, '^(SH|SY_0005)')

在 SQL Server 中执行它的等效方法是什么?

【问题讨论】:

  • C_column LIKE 'SH%' OR C_column = 'SY_0005' 是您在 SQL Server 中可以做的最好的事情,除非您想使用正则表达式 UDF。

标签: sql sql-server regex sql-like


【解决方案1】:
select *
from TABLE
where A_column like 'A%' AND B_column = '5' AND
(C_column like 'SH%' or C_column = 'SY_0005')

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 2022-01-03
    • 2017-03-22
    相关资源
    最近更新 更多