문제
모두, 나는 이것을 제대로 표현하는 데 어려움을 겪고 있기 때문에 온라인으로 답을 찾는 데 어려움을 겪고 있기 때문에 내가 할 수있는 최선은 예를 들어 보는 것입니다. 다음 데이터베이스 테이블이 있습니다.
ACTORNAME SERIESNAME
------------------------------ ------------
baldwin found
baldwin lost
baldwin rocks
baldwin sienfield
costelo friends
costelo prince
costelo remember
denzel friends
denzel prince
denzel remember
fox found
fox friends
fox prince
lopez found
lopez friends
lopez prince
lopez remember
pitt er
pitt everybody
pitt friends
pitt heroes
pitt rocks
smith friends
smith prince
smith remember
그리고 나는 스미스가 연주하는 것과 같은 시리즈에서 연주하는 배우들을 잡을 수있는 선정 된 진술을 사용하고 싶습니다.
Costelo, Denzel 및 Lopez
어떤 키워드를 사용할지 잘 모르겠습니다. 나는 Join 명령을보고 있었고 마이너스를 시도했는데, 내가 얻을 수있는 가장 가까운 것은 Smith가 연주하는 것과 같은 시리즈에서 정확히 연주하는 Actornames였습니다 (그 상황에서 Lopez는 포함되지 않고 잘못되었습니다).
다음은 또 다른 설명입니다.
suppose Smith acts in movies X and Y.
Suppose also that actor
A acts in movies X, Z
B acts in Y
C acts in X, Y, Z
D acts in X, Y
The answer to the query should be actors C and D.
다시 말해, 당신은 영화 세트에 배우 스미스의 영화를 포함하는 배우를 반환해야합니다.
올바른 방향을 추진하기 위해, Tomek
해결책
죄송합니다. 나의 원래 대답은 당신의 의도를 오해했습니다. 대신 시도해보십시오.
select t2.actorname,
count(t2.seriesname)
from mytable t1
join mytable t2
on t1.seriesname=t2.seriesname and t1.actorname='smith' and t2.actorname <> 'smith' group by t2.actorname
having count(t2.seriesname)=(select count(seriesname) from mytable where actorname='smith')
다른 팁
SELECT DISTINCT ActorName
FROM dbo.MyTable
WHERE SeriesName IN (SELECT SeriesName FROM dbo.MyTable WHERE ActorName = 'smith');
제휴하지 않습니다 StackOverflow