[英]SQL Subquery as expression
我有以下兩個表:
Create Table #Claims (ClaimId int, FormType varchar(3), AdjustmentVersion int)
Create Table #Secondary (FeeId int, FeeName varchar(60))
我希望能夠返回所有屬於特定 FormType 和 AdjustmentVersion 的聲明。
鑒於以下查詢:
select * from #Claims where FormType = 'DEN' and AdjustmentVersion in (1,2,3,(select FeeId from #Secondary))
如何更正語法以同時匹配給定整數和子查詢上的 AdjustmentVersion? 目前,我收到錯誤“子查詢返回了多個結果”。
我嘗試使用和或與 AdjustmentVersion 但最終忽略了 FormType = 'DEN'
您可以將值分成兩組,文字和子查詢:
select *
from #Claims
where FormType = 'DEN' and
( AdjustmentVersion in (1,2,3) or AdjustmentVersion in (select FeeId from #Secondary) );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.