我老了并且总是使用“+”符号来表示外部,但是这个sql在sql server中不起作用。有人可以帮助我将以下sql转换为新的“左外连接”格式。
select frdonmst.FRID,
fradrmst.adrseq,
fax.phone as fax,
phone.phone as phone
from frdonmst,
fradrmst,
frphnmst fax,
frphnmst phone
where frdonmst.frid = fradrmst.frid
and frdonmst.adrseq = fradrmst.adrseq
and ( frdonmst.frid = fax.frid(+)
and frdonmst.adrseq = fax.adrseq(+)
and fax.phtyp(+) = 'FAX1' )
and ( frdonmst.frid = phone.frid(+)
and frdonmst.adrseq = phone.adrseq(+)
and phone.phtyp(+) = 'D1' )
答案 0 :(得分:5)
我会试一试,但我从来没有见过这个容量中使用的加号。 :)
SELECT a.FRID
, b.adrseq
, fax.phone AS fax
, phone.phone AS phone
FROM frdonmst a
JOIN fradrmst b
ON a.adrseq = b.adrseq
LEFT JOIN frphnmst fax
ON a.frid = fax.frid
AND a.adrseq = fax.adrseq
AND fax.phtyp = 'FAX1'
LEFT JOIN frphnmst phone
ON a.frid = phone.frid
AND a.adrseq = phone.adrseq
AND phone.phtyp = 'D1'
P.S。刚刚手工输入,我礼貌地建议使用单词来命名。
答案 1 :(得分:0)
我希望这就是你要找的东西:
select
frdonmst.FRID,
fradrmst.adrseq,
faxTable.phone as fax,
phoneTable.phone as phone
FROM (((frdonmst LEFT JOIN fradrmst ON frdonmst.adrseq = fradrmst.adrseq and frdonmst.adrseq = fradrmst.adrseq)
LEFT JOIN frphnmst AS faxTable ON frdonmst.frid = faxTable.frid AND frdonmst.adrseq = faxTable.adrseq)
LEFT JOIN frphnmst AS phoneTable ON frdonmst.frid = phoneTable.frid AND frdonmst.adrseq = phoneTable.adrseq)
WHERE faxTable.phtyp='FAX1' AND phoneTable.phtyp='D1'