代码之家  ›  专栏  ›  技术社区  ›  George Menoutis

旧样式到新样式的联接转换

  •  -1
  • George Menoutis  · 技术社区  · 7 年前

    请考虑以下代码:

    select (some columns)
    from efdan_setup a,crit_efdan_val b,efdan c
    where a.dan *= c.code
    and b.codef *= c.codef
    and b.mhnmis *= c.mhnmis
    and b.etmis *= c.etmis
    and b.ebdmis *= c.ebdmis
    and b.mhnet *= c.mhnet
    and b.mhnet_plir *= c.mhnet_plir
    

    我不太熟悉老式的连接方式,我已经读了足够多的内容来理解我应该改变这一点。我想知道哪一种是新样式的等边三角形。我猜想:

    from 
        crit_efdan_val b
        left join efdan c on 
            b.codef = c.codef 
            and b.mhnmis = c.mhnmis 
            and b.etmis = c.etmis 
            and b.ebdmis = c.ebdmis 
            and b.mhnet = c.mhnet
            and b.mhnet_plir = c.mhnet_plir
        right join fdan_setup a on a.dan = c.code
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Zohar Peled    7 年前

    你就快到了——但是混合左连接和右连接几乎和混合物质和反物质一样糟糕。
    事实上,有些人(包括我自己)宁愿完全避免右连接,只坚持左连接。

    我可以这样写:

    from efdan_setup a
    left join efdan c
        on a.dan = c.code
    left crit_efdan_val b
        on b.codef = c.codef
        and b.mhnmis = c.mhnmis
        and b.etmis = c.etmis
        and b.ebdmis = c.ebdmis
        and b.mhnet = c.mhnet
        and b.mhnet_plir = c.mhnet_plir