【问题标题】:Oracle SQL different where clauses with case whenOracle SQL 不同的 where 子句与 case when
【发布时间】:2021-06-07 09:31:25
【问题描述】:

愚蠢的问题,因为我想用 where 子句的两个选项开始一个 select 语句,并停留在我可以过滤它的部分。问题是,我希望选项说“如果 RS_BEM 是 A1 或 A2,则搜索不在列表中的 ID,如果还有其他搜索在列表中的 ID”。

and Case when :RS_BEM like 'A1' or :RS_BEM like 'A2' then ate_msg_nr not in (select * from StoerIDs) else ate_msg_nr in (select * from StoerIDs) end

我敢打赌这非常容易,但不知何故我没有看到它。

【问题讨论】:

    标签: sql oracle case where-clause


    【解决方案1】:

    使用ANDOR 和括号:

    where (:RS_BEM in ('A1', 'A2') and ate_msg_nr not in (select * from StoerIDs))
       or (:RS_BEM not in ('A1', 'A2') and ate_msg_nr in (select * from StoerIDs))
    

    【讨论】:

    • 非常感谢。就是这样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-21
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    相关资源
    最近更新 更多