多表聯查,兩表之間相互關聯,不一定需要有主外來鍵關係,欄位匹配就行
阿新 • • 發佈:2019-02-06
Set @dlr = 15001;
SELECT school.name AS schoolName, xq.xqmc AS xqmc, qy.mc as qymc, ly.bz as lymc, fj.bz as fjmc FROM t_xsgy_ssap ssap
LEFT JOIN t_xsgy_cwgl cwgl ON cwgl.id=ssap.cwid
LEFT JOIN t_baseinfo_fj fj ON fj.id = cwgl.fj
LEFT JOIN t_baseinfo_ly ly ON fj.lyid = ly.id
LEFT JOIN t_baseinfo_qy qy ON ly.qyid = qy.id
LEFT JOIN t_sys_school school ON ssap.ssxxid = school.id
LEFT JOIN t_baseinfo_xq xq ON qy.ssxq = xq.id
WHERE ssap.xhid = @dlr
AND ssap.zszt =1
SELECT school.name AS schoolName, xq.xqmc AS xqmc, qy.mc as qymc, ly.bz as lymc, fj.bz as fjmc FROM t_xsgy_ssap ssap
LEFT JOIN t_xsgy_cwgl cwgl ON cwgl.id=ssap.cwid
LEFT JOIN t_baseinfo_fj fj ON fj.id = cwgl.fj
LEFT JOIN t_baseinfo_ly ly ON fj.lyid = ly.id
LEFT JOIN t_baseinfo_qy qy ON ly.qyid = qy.id
LEFT JOIN t_sys_school school ON ssap.ssxxid = school.id
LEFT JOIN t_baseinfo_xq xq ON qy.ssxq = xq.id
WHERE ssap.xhid = @dlr
AND ssap.zszt =1