質問

すべて、私はこれをきちんと言い表すのが難しいので、オンラインで答えを見つけるのに苦労しているので、私ができる最善のことは例を挙げることです。次のデータベーステーブルがあります。

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

そして、スミスが演じる同じシリーズのすべてで演じる俳優名を取得するSELECTステートメントを使用したいと思います。したがって、結果の俳優名は次のようになります。

costelo、denzel、およびlopez

どのキーワードを使用するのかさえわかりません。 JOINコマンドを見て、MINUSも試してみました。最も近いのは、スミスが演じるのとまったく同じシリーズで演じる俳優名でした(その状況では、ロペスは含まれておらず、間違っています)

別の説明を次に示します。

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');
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top