怎么没有人回答:是不是我的题意表述这不清呀?
下面我做的答案:
请大家指正一下:
三者都不相等的交集,也可以单独显示。 (交集的SQL语句如何写)
select te.ITEM_CODE,C.PRODUCT_CODE,te.INVOICE AS PO_NO, te.SO_NUMBER, te.INDATE AS PO_LASTUPDATE,
te.DESC1, te.UPRICE AS PO_UPRICE,te.LAST_PRICE,C.UPRICE AS COSTSHEETUPRICE,te.CRT_USER AS PO_CREATEUSER ,te.CRT_DATE AS ITEM_LASTUPDATE
from (SELECT P.ITEM_CODE,P.INVOICE, P.SO_NUMBER, P.INDATE,
P.DESC1, P.UPRICE,I.LAST_PRICE,H.CRT_USER,I.CRT_DATE
FROM PO_LN1 P ,PO_HEAD1 H ,UN_ITEM1 I
WHERE P.ITEM_CODE=I.ITEM_CODE
AND H.PO_NUMBER =P.INVOICE
AND P.UPRICE<>I.LAST_PRICE
AND SUBSTRING(P.ITEM_CODE,9,1)='1'
AND P.CRRNCY NOT LIKE 'RMB'
AND P.CRRNCY NOT LIKE 'USD'
) as te
inner join CS_METAL C
ON C.ITEM_CODE=te.ITEM_CODE
and (C.UPRICE<>te.UPRICE or C.UPRICE<>te.LAST_PRICE)
and
SUBSTRING(C.PRODUCT_CODE,9,1)='1'
ORDER BY C.ITEM_CODE,C.PRODUCT_CODE, te.INVOICE
---结果查询的结果会比原来两张表总记录数减去相同行的数后,还多了2行
三者只要有任何二者不等的话,就可以显示, (并集的SQL语句如何写)
select te.ITEM_CODE,C.PRODUCT_CODE,te.INVOICE AS PO_NO, te.SO_NUMBER, te.INDATE AS PO_LASTUPDATE,
te.DESC1, te.UPRICE AS PO_UPRICE,te.LAST_PRICE,C.UPRICE AS COSTSHEETUPRICE,te.CRT_USER AS PO_CREATEUSER ,te.CRT_DATE AS ITEM_LASTUPDATE
from (SELECT P.ITEM_CODE,P.INVOICE, P.SO_NUMBER, P.INDATE,
P.DESC1, P.UPRICE,I.LAST_PRICE,H.CRT_USER,I.CRT_DATE
FROM PO_LN1 P ,PO_HEAD1 H ,UN_ITEM1 I
WHERE P.ITEM_CODE=I.ITEM_CODE
AND H.PO_NUMBER =P.INVOICE
AND SUBSTRING(P.ITEM_CODE,9,1)='1'
AND P.CRRNCY NOT LIKE 'RMB'
AND P.CRRNCY NOT LIKE 'USD'
) as te
inner join CS_METAL C
ON C.ITEM_CODE=te.ITEM_CODE
and (C.UPRICE<>te.UPRICE or te.UPRICE<>te.LAST_PRICE or C.UPRICE<>te.UPRICE )
and SUBSTRING(C.PRODUCT_CODE,9,1)='1'
ORDER BY C.ITEM_CODE,C.PRODUCT_CODE, te.INVOICE
--结果查询出现的结果比两张查询的结果之和还多出100多条记录,
高手能不能帮忙分析一下?