表A拉回表B中的行。如果表B的col2是'XYZ',那麼我只需要包含該yy的XYZ的行。如何在oracle中創建條件where子句sql
Table A Table B
id bid bid col2
1 2 2 ABC
1 3 3 ABC
2 4 4 ABC
2 5 5 XYZ
輸出應該有3行總共兩行編號1和1個一行ID 2.
這是我迄今試圖
select * from table a, table b
where a.col1 = b.col1
and if 'ABC' in (select b1.col2 from table b1 where b1.col1 = b.col1) then b.col2 = 'ABC' end
and if 'XYZ' in (select b1.col2 from table b1 where b1.col1 = b.col1) then b.col2 = 'XYZ' end
我也曾嘗試
and case when (select count(b1.col) from table b1 where b1.col = b.col1 and b1.col = 'XYZ') >0 then b.col1 = 'XYZ' end
確切的代碼
select *
from scores a, queues b
where res_id = '112321'
and b.que_id = a.que_id
and case when (select count(qasgn_cd) from queues where que_id = b.que_id and QASGN_CD = 'BTQFR') >0 then b.que_id = '1' else FALSE end
給出了一個錯誤ORA-00905:缺少關鍵字
爲您的案例添加'else'子句/如果使用'false'值。例如:'case when x then y else FALSE end' - 如果返回false,則該行將從結果中被丟棄 –
它說我錯過了一個關鍵詞,如果我在else語句中放置false,它會給出一個無效錯誤 – user1854438
用確切代碼更新您的問題並返回錯誤消息 –