0

我有一张桌子:

     Subject_ID StudyPlan_ID   
       271            2   
       279            2  
       276            2  
       279            8 
       271            8   
       267            9   
       279            9   

我想找到它们Subject_ID之间的共同点,StudyPlan_ID所以它279使用的是 SqlServer 2008 所以请大家帮忙。

4

1 回答 1

1

如果我理解正确,您的意思是找到链接到每个 StudyPlan_ID 的 Subject_ID。

DECLARE @Data TABLE(Subject_ID int, StudyPlan_ID int)
INSERT INTO @Data
    VALUES
        (271, 2),
        (279, 2),
        (276, 2),
        (279, 8),
        (271, 8), 
        (267, 9),
        (279, 9)

SELECT Subject_ID
FROM @Data AS a
GROUP BY Subject_ID
HAVING COUNT(Distinct StudyPlan_ID) = (SELECT COUNT(Distinct StudyPlan_ID) FROM @Data)
于 2012-05-28T16:02:43.053 回答