我正在从From t2 OI Join t3 OPL ON OI.c1 = OPL.P1 join t4 sp on sp.c2 = OI.p2 where sp.ID ='IQ')
获取第1组产品,ID
它适用于Group1和Product,但带有ID我面临问题
我想将ID与R.ID进行比较,然后需要检索该值
我该怎么办?
(SELECT Top 1 (CASE WHEN Group1='p'
THEN (Case when Product='10'
THEN(Select top 1 Email from t1 as R join t2 as E
on R.C1=E.E1 where R.ID=ID
)
ELSE (Select top 1 Email from t1 as R join t2 as E
on R.B1=E.E1 where R.ID=ID
)
END)
ELSE
(Select top 1 Email from t1 as R join t2 as E
on R.A1=E.E1 where R.ID=ID
)
END) AS Email
From t2 OI
Join t3 OPL ON OI.c1 = OPL.P1
join t4 sp on sp.c2 = OI.p2
where sp.ID ='IQ')