日期:2014-05-18 浏览次数:20446 次
SELECT a1.[name] AS p1, a2.[name] AS p2, a3.[name] AS p3, a4.[name] As P4, c.bs AS bs FROM (SELECT [scheme] AS hm_scheme FROM D UNION SELECT znum FROM E) B JOIN (SELECT [name], ID from A Where CID = 1) a1 ON a1.ID = B.hm_scheme JOIN (SELECT [name], ID from A Where CID = 2) a2 ON a2.ID = B.hm_scheme JOIN (SELECT [name], ID from A Where CID = 3) a3 ON a3.ID = B.hm_scheme JOIN (SELECT [name], ID from A Where CID = 4) a4 ON a4.ID = B.hm_scheme JOIN C ON C.ID = B.hm_scheme
------解决方案--------------------
SELECT p1,p2,p3,p4,bs FROM (SELECT scheme, Stime FROM D UNION ALL SELECT znum, Ztime FROM E) B join (SELECT p1=name FROM A WHERE CID = 1) AS T1 on B.scheme=T1.ID join (SELECT p2=name FROM A WHERE CID = 2) AS T2 on B.scheme=T2.ID join (SELECT p3=name FROM A WHERE CID = 3) AS T3 on B.scheme=T3.ID join (SELECT p4=name FROM A WHERE CID = 4) AS T4 on B.scheme=T4.ID join (SELECT bs FROM C ) AS T5 on B.scheme=T5.ID
------解决方案--------------------
Generics
的方法可以参考
------解决方案--------------------
把join改为left join即可。