查询缺少结果

时间:2015-08-20 21:57:48

标签: sql db2 subquery

原始查询会提取所有正确的数据。子查询单独正确地提取所有数据。放在一起时,完整查询错过了8行。

$(document).ready(function(){
var urlpage = window.location.href;
    regex = /http\:\/\/www\.mysite\.com\/mypage.php\?([a-zA-Z]+)/;
    var texturl = urlpage.match(regex)[1]; 
    if(texturl !== null)
    {
    document.getElementById('idmyinput').value= texturl;
    }

});

什么会导致查询只错过几个订单号?

1 个答案:

答案 0 :(得分:0)

在子查询中,在最后一个内部条件中使用不带“_1”的别名:

INNER JOIN TSA400.NRPDTA.IMA IMA_1 ON S3O_1.S3ITNO = IMA.IMITNO

将您的外部条件“S3O_1.S3ITNO = IMA.IMITNO”复制到

所以,结果将是

SELECT 
    TMRQD,
    TMCUST,
    TMNAME,
    S3ON,
    S3ORQT,
    S3ITNO,
    IMDESC,
    S3DTSTO,
    S3DTNSEQ# 
FROM 
         TSA400.NRPDTA.S3C S3O RIGHT OUTER JOIN TSA400.NRPDTA.SOP114F1 SOP114F1 ON S3O.S3ON = SOP114F1.TMON
        LEFT OUTER JOIN TSA400.NRPDTA.S3DTU S3DTU ON SOP114F1.TMON = S3DTU.S3DTON
        INNER JOIN TSA400.NRPDTA.IMA IMA ON S3O.S3ITNO = IMA.IMITNO
    WHERE
          S3DTNSEQ# = (
    SELECT
          MAX(S3DTNSEQ#)
    FROM 
        TSA400.NRPDTA.S3C S3O_1 RIGHT OUTER JOIN TSA400.NRPDTA.SOP114F1 SOP114F1_1  ON S3O_1.S3ON = SOP114F1_1.TMON
        LEFT OUTER JOIN TSA400.NRPDTA.S3DTU S3DTU_1 ON SOP114F1_1.TMON = S3DTU_1.S3DTON
        INNER JOIN TSA400.NRPDTA.IMA IMA_1 ON S3O_1.S3ITNO = IMA_1.IMITNO
    WHERE S3O_1.S3ITNO = IMA.IMITNO
    GROUP BY
             S3ITNO)

    OR S3DTNSEQ# IS NULL

    GROUP BY
            TMRQD,
            TMCUST,
            TMNAME,
            S3ON,
            S3ORQT,
            S3ITNO,
            IMDESC,
            S3DTSTO,
            S3DTNSEQ# 
ORDER BY S3ON