私の全体の最初の試みをスクラップするように編集。それは間違った答えでした。私の新しい答えは:
declare @usersToFind table (userid int)
insert into @usersToFind
select 11
union all select 12
union all select 13
select p.convid, count(*) [participantCount]
from
@participants p
left join @conversations c
on p.convid = c.id
where
p.userid in (select userid from @usersToFind)
group by
p.convid
-- identify all conversation columns you care about here, and repeat them in select clause
having
count(distinct p.userid) >= (select count(*) from @usersToFind)
問題は、検索する特定のユーザーのリストを受け入れないということでした。これは、あなたが何人を指定しても、すべてのユーザーが上記の会話の参加者であるすべての会話を見つけます。
興味を持っている場合は、ここで私は私のテストを設定するために使用されるSQLは次のとおりです。
declare @conversations table (id int)
declare @participants table (userid int, convid int)
insert into @conversations values (100)
insert into @conversations values (200)
insert into @conversations values (300)
insert into @conversations values (400)
insert into @participants values (11, 100)
insert into @participants values (12, 100)
insert into @participants values (13, 100)
insert into @participants values (11, 200)
insert into @participants values (12, 200)
insert into @participants values (11, 300)
insert into @participants values (13, 300)
insert into @participants values (12, 400)
insert into @participants values (13, 400)
(さらにまた
このことによって、グループではありませんでした選択リストから列を削除するように編集あなたの投稿を編集することはできますか?私はダウンフォートを削除します;これはうまくいかないかもしれませんが(またはそれはわかりません) –
@JeremyHolovacsこれは私がダウンしたものとは違って見えます。当時のそれをより明確にしたはずです!私の元の答えを投稿した直後、私は "あなたは何を考えていたのですか?"と終わり、私は戻ってきました。もう一度。 –
これは2人の参加者にとって美しく、簡単に機能しますが、3人目の参加者のために交差/選択を繰り返す必要があります。 –