gpt4 book ai didi

sql-server - 将旧的 "+"Join 转换为 SQL Server 语法?

转载 作者:行者123 更新时间:2023-12-02 05:39:51 25 4
gpt4 key购买 nike

我是老派,一直用“+”号来表示外部,但是这个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' )

最佳答案

我会试一试,但我从未见过在这种情况下使用加号。 :)

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'

附言刚刚用手打出来,我会礼貌地建议使用单词来命名事物。

关于sql-server - 将旧的 "+"Join 转换为 SQL Server 语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11164320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com