[英]SQL - AND STATEMENT INSIDE RESULT CASE STATEMENT
我想執行類似的事情
select * from table1
inner join table2 on table1.numero=table2.numero
CASE WHEN table2.test = 'test'
THEN and table2.test = table1.test END
我的意思是如果我有table2.test ='test',那么table2.test = table1.test
謝謝
select * from table1
inner join table2 on table1.numero=table2.numero
and CASE WHEN table2.test = 'test' then table2.test else 1 end
= CASE WHEN table2.test = 'test' then table1.test else 1 end
使用兩個case語句,您可以構造when when table2.test = test然后table2.test = table1.test else 1 = 1。 我認為那是您要做什么?
嘗試這個 ...
SELECT *
FROM
table1
INNER JOIN
table2 ON
table1.numero=table2.numero AND
((Table2.Test = 'test' AND Table1.test = Table2.test) OR Table2.Test != 'test')
當我執行此查詢
select * from table1
inner join table2 on table1.numero=table2.numero
and CASE WHEN table2.test = 'test' then table2.test else 1 end
= CASE WHEN table2.test = 'test' then table1.test else 1 end
我有一個錯誤
“語法不正確vers'='。”
對於第二個查詢,為什么我們要聲明?或者我認為這是正確的,例如:
SELECT *
FROM
table1
INNER JOIN
table2 ON
table1.numero=table2.numero AND
((Table2.Test = 'test' AND Table1.test = Table2.test))
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.