WHERE 子句中的嵌套 CASE 语句
我正在尝试使用嵌套 CASE 语句(下方粗体),其中基于第一个 CASE 语句,我需要验证内部 where 子句,否则验证其他内部 where 子句。使用嵌套 CASE When 语句时,以下方法是正确的吗?
SELECT COUNT(*)
FROM <list of table>
WHERE <list of conditions >
AND CASE WHEN cond1 <> 1 or cond2 <>2 or cond3 <> 3
THEN
WHEN ( col1,col2,col3) NOT IN (SELECT col1,col2,col3
FROM table 1,table 2
WHERE <condition1> )
ELSE ( col1,col2,col3,col4) NOT IN (SELECT col1,col2,col3,col4
FROM table 1,table 2
WHERE <condition2> )
END
I am trying to use NESTED CASE statement(BOLD Below) where, based on first CASE statment, I need to verify inner where clause, else other inner where clause. Is below right approach when using nested CASE When statements?
SELECT COUNT(*)
FROM <list of table>
WHERE <list of conditions >
AND CASE WHEN cond1 <> 1 or cond2 <>2 or cond3 <> 3
THEN
WHEN ( col1,col2,col3) NOT IN (SELECT col1,col2,col3
FROM table 1,table 2
WHERE <condition1> )
ELSE ( col1,col2,col3,col4) NOT IN (SELECT col1,col2,col3,col4
FROM table 1,table 2
WHERE <condition2> )
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

使用
AND
和OR
:注意:不要使用旧版逗号连接,请使用现代 ANSI 连接语法。
Use
AND
andOR
:Notes: Do not use legacy comma joins, use the modern ANSI join syntax.