左外部联接失败

时间:2018-11-08 15:43:06

标签: mysql sql

您好,如果我在VBFA.VBTYP_N = 'Q'的条件上添加了该查询,并且正在提供null数据,并且在where条件中添加了相同的结果,则此查询不起作用。两种情况都是相同的结果

即使条件失败,我也需要从左表中获取数据

ORDER_DATA = SELECT

          VBRP.MATNR AS ITEM,
          VBRP.ARKTX AS ITEMDESCRIPTION,
          VBAK.ERDAT AS ORDERDATE,
          VBAK.VBELN AS ORDERNUMBER,
          VBRK.FKDAT AS INVOICEDATE,
          VBRK.VBELN AS INVOICENUMBER ,
          VBRP.FKIMG AS QUANTITY,
          VBRP.VRKME AS UOM,
          VBFA.RFMNG AS PICKUNIT
          FROM  VBAP

          INNER JOIN VBAK
          ON   VBAP.MANDT = VBAK.MANDT
          AND  VBAP.VBELN = VBAK.VBELN

          LEFT  OUTER JOIN VBRP
          ON  VBAP.MANDT = VBRP.MANDT
          AND VBAP.VBELN = VBRP.AUBEL
          AND VBAP.POSNR = VBRP.AUPOS

         LEFT OUTER JOIN VBFA

          ON  VBRP.VGBEL = VBFA.VBELV
          AND  VBRP.VGPOS = VBFA.POSNV
          AND VBFA.VBTYP_N = 'Q'

          INNER JOIN VBRK
          ON  VBRP.MANDT = VBRK.MANDT
          AND VBRP.VBELN = VBRK.VBELN






          WHERE VBAP.MANDT = :CLNT AND
                VBAK.MANDT = :CLNT AND

1 个答案:

答案 0 :(得分:0)

如果您的VBFA.VBTYP_N列中包含NULL值,并且这是失败的加入条件的原因,那么您可以尝试使用以下方法: AND(VBFA.VBTYP_N为NULL或VBFA.VBTYP_N ='Q')