我正在尝试使用此查询仅获取具有唯一区域 = 200 的 rtp.releaseid
select rtp.ReleaseId, rtp.TerritoryId from ReleaseTerritoryPrice rtp where
rtp.TerritoryId=200
但我想有些东西不见了,你能帮忙吗?谢谢。
我正在尝试使用此查询仅获取具有唯一区域 = 200 的 rtp.releaseid
select rtp.ReleaseId, rtp.TerritoryId from ReleaseTerritoryPrice rtp where
rtp.TerritoryId=200
但我想有些东西不见了,你能帮忙吗?谢谢。
NOT EXISTS
您可以在 WHERE 子句中使用以下内容:
select rtp1.releaseId, rtp1.territoryId
from ReleaseTerritoryPrice rtp1
where rtp1.territoryId = 200
and not exists (select releaseId
from ReleaseTerritoryPrice t2
where t2.territoryId <> 200
and rtp1.releaseId = t2.releaseId);
或者您可以NOT IN
在 WHERE 子句中使用:
select rtp1.releaseId, rtp1.territoryId
from ReleaseTerritoryPrice rtp1
where rtp1.territoryId = 200
and rtp1.releaseId not in (select releaseId
from ReleaseTerritoryPrice t2
where t2.territoryId <> 200);
也许你的意思是这个
SELECT MAIN.* FROM ReleaseTerritoryPrice MAIN
WHERE MAIN.ReleaseId in (
SELECT rtp.ReleaseId
FROM ReleaseTerritoryPrice rtp
WHERE rtp.TerritoryId =200
GROUP BY rtp.ReleaseId
HAVING COUNT(rtp.TerritoryId) =1 )
几种方法
SELECT ReleaseId
FROM ReleaseTerritoryPrice
WHERE TerritoryId = 200
EXCEPT
SELECT ReleaseId
FROM ReleaseTerritoryPrice
WHERE TerritoryId IS NULL OR TerritoryId <> 200
或者
SELECT ReleaseId
FROM ReleaseTerritoryPrice
GROUP BY ReleaseId
HAVING COUNT(DISTINCT TerritoryId) =1 AND MAX(TerritoryId )=200
使用DISTINCT关键字。
select DISTINCT rtp.ReleaseId,
rtp.TerritoryId
from ReleaseTerritoryPrice rtp
where rtp.TerritoryId=200