數組如果我的理解是正確的,你可以很容易地找到究竟是誰b中的成員之前在同一個房間。
CREATE TABLE roomMembers
(
roomid int,
member varchar(10)
);
INSERT INTO roomMembers VALUES (0,'Member1')
INSERT INTO roomMembers VALUES (0,'Member2')
INSERT INTO roomMembers VALUES (0,'Member3')
INSERT INTO roomMembers VALUES (1,'Member1')
INSERT INTO roomMembers VALUES (1,'Member2')
INSERT INTO roomMembers VALUES (1,'Member4')
這應該會給你所有的房間,多人留下來。
WITH q1
AS (
SELECT member
,count(*) total_count
FROM [dbo].[roomMembers]
GROUP BY member
HAVING count(*) > 1
)
SELECT r.roomid
,q1.member
FROM q1
JOIN dbo.roomMembers r ON r.member = q1.member
order by r.roomid;
希望這會有所幫助!
您能否給我們提供您期待的輸出結果的樣本?我無法理解你想要完成什麼。 – FutbolFan