SQL Server中的SQL子查询

时间:2020-12-01 23:29:36

The first table is pre and the second is tran. I want the S_SSN from tran where no and Code of transcript matches with Code and no in pre

第一个表是pre,第二个表是tran。我希望S_SSN来自tran,其中no和Transcript的代码与Code匹配,而pre和no

1 个解决方案

#1


1  

Is this what you want?

这是你想要的吗?

;WITH Cte AS(
    SELECT
        t.Student_SSN,
        cc = COUNT(t.Student_SSN)
    FROM transcript t
    INNER JOIN prereq p
        ON t.C_no = p.P_no
        AND t.D_Code = p.P_Code
    WHERE
        p.D_Code = 'INFS' 
        AND p.C_no = 614
    GROUP BY t.Student_SSN
)
SELECT DISTINCT Student_SSN
FROM Cte
WHERE cc = (SELECT COUNT(*)
            FROM prereq  p
            WHERE p.D_Code = 'INFS' AND p.C_no = 614)

#1


1  

Is this what you want?

这是你想要的吗?

;WITH Cte AS(
    SELECT
        t.Student_SSN,
        cc = COUNT(t.Student_SSN)
    FROM transcript t
    INNER JOIN prereq p
        ON t.C_no = p.P_no
        AND t.D_Code = p.P_Code
    WHERE
        p.D_Code = 'INFS' 
        AND p.C_no = 614
    GROUP BY t.Student_SSN
)
SELECT DISTINCT Student_SSN
FROM Cte
WHERE cc = (SELECT COUNT(*)
            FROM prereq  p
            WHERE p.D_Code = 'INFS' AND p.C_no = 614)