|
|
#4
pzywillpan2017-08-04 12:08
if object_id('tempdb..t1') is not null drop table t1
CREATE TABLE T1 (ID INT,TYPE VARCHAR(50))
INSERT INTO T1 (ID,TYPE)
VALUES (1,'A'),(2,'B'),(3,'C'),(4,'D')
if object_id('tempdb..t2') is not null drop table t2
CREATE TABLE T2 (ID INT,CODE VARCHAR(50),ID2 INT)
INSERT INTO T2 (ID,CODE,ID2)
VALUES (1,1,1),(2,2,2),(3,1,3),(4,2,3),(5,1,4),(6,2,4)
SELECT CODE FROM T1 INNER JOIN T2 ON T1.ID = T2.ID2
WHERE TYPE = 'A'
SELECT CODE FROM T1 INNER JOIN T2 ON T1.ID = T2.ID2
WHERE TYPE = 'B'
SELECT CODE FROM T1 INNER JOIN T2 ON T1.ID = T2.ID2
WHERE TYPE = 'C'
SELECT CODE FROM T1 INNER JOIN T2 ON T1.ID = T2.ID2
WHERE TYPE = 'D'
不知道是不是你要的结果,可以参考一下
|