简体   繁体   中英

SQL sub query in SQL Server

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM