下面的查询返回所有只有 regionid =200 的 releaseID
select rt.ReleaseId from ReleaseTerritory rt
group by rt.ReleaseId
having SUM(case when rt.TerritoryId=200 then 0 else 1 end)=0
我该如何检查上面查询的结果中是否存在值47033。非常感谢。
下面的查询返回所有只有 regionid =200 的 releaseID
select rt.ReleaseId from ReleaseTerritory rt
group by rt.ReleaseId
having SUM(case when rt.TerritoryId=200 then 0 else 1 end)=0
我该如何检查上面查询的结果中是否存在值47033。非常感谢。
添加一个 where 子句,将返回的结果限制为特定的ReleaseId
.
select rt.ReleaseId from ReleaseTerritory rt
where rt.ReleaseId = 47033
group by rt.ReleaseId
having SUM(case when rt.TerritoryId=200 then 0 else 1 end)=0
要接收诸如yes or exists
(警告未经测试的代码)之类的值:
select case when count(rt.ReleaseId) = 0
then 'Doesnt Exist'
else 'Exists' end as exists
from ReleaseTerritory rt
where rt.ReleaseId = 47033
group by rt.ReleaseId
having SUM(case when rt.TerritoryId=200 then 0 else 1 end)=0
select ReleaseId from ReleaseTerritory
where ReleaseId = 47033
and TerritoryId=200
except
select ReleaseId from ReleaseTerritory
where ReleaseId = 47033
and TerritoryId <> 200