3

我正在尝试比较 A.BUSINESS_UNIT_PO、A.PO_ID、A.LINE_NBR 上 2 个表之间的数量总和。下面的查询对我不起作用。你们谁能告诉我这个查询中的问题。

SELECT A.BUSINESS_UNIT_PO,
       A.PO_ID, 
       A.LINE_NBR 
 FROM PS_BCT_DTL A
WHERE A.BCT_DET_STATUS=1
  AND SUM(A.QTY) = (SELECT SUM(B.QTY_SH_RECVD) 
                     FROM PS_RECV_LN_SHIP B
                    WHERE A.BUSINESS_UNIT_PO=B.BUSINESS_UNIT_PO
                      AND A.PO_ID= B.PO_ID
                      AND A.LINE_NBR= B.LINE_NBR
                     )
GROUP BY A.BUSINESS_UNIT_PO,A.PO_ID, A.LINE_NBR
4

2 回答 2

5

尝试having如下使用:

SELECT A.BUSINESS_UNIT_PO,
       A.PO_ID, 
       A.LINE_NBR,
       SUM(A.QTY) 
FROM PS_BCT_DTL A
WHERE A.BCT_DET_STATUS=1    
GROUP BY A.BUSINESS_UNIT_PO,A.PO_ID, A.LINE_NBR
having SUM(A.QTY) =(SELECT SUM(B.QTY_SH_RECVD) 
                 FROM PS_RECV_LN_SHIP B
                 WHERE A.BUSINESS_UNIT_PO=B.BUSINESS_UNIT_PO
                 AND A.PO_ID= B.PO_ID
                 AND A.LINE_NBR= B.LINE_NBR)

是有关拥有的更多信息。

于 2012-10-03T18:00:35.133 回答
2
select
  A.BUSINESS_UNIT_PO,A.PO_ID,A.LINE_NBR,
  sum(a.qty) sumA,
  sum(b.qty) sumB
from
  a inner join
  b on 
   A.BUSINESS_UNIT_PO=B.BUSINESS_UNIT_PO AND 
   A.PO_ID= B.PO_ID  AND 
   A.LINE_NBR= B.LINE_NBR
group by
 A.BUSINESS_UNIT_PO,A.PO_ID,A.LINE_NBR
having
  sum(a.qty) = sum(b.qty);
于 2012-10-03T18:12:27.553 回答