2017-04-26 28 views
0

我想從兩個表無法從兩個表

select AVP_KEY 
(SELECT AVP_KEY FROM AVP_KEY WHERE AVP_KEY in(SELECT DISTINCT NEW_AVP_KEY FROM GTT_STG_ITEM_ATTR_AVP WHERE ATTRIBUTE_GROUP_ID IN(SELECT ATTRIBUTE_GROUP_ID FROM GTT_STG_ITEM_ATTR_AVP WHERE INSERT_TYPE=2 
MINUS 
SELECT ATTRIBUTE_GROUP_ID FROM GTT_STG_ITEM_ATTR_AVP WHERE INSERT_TYPE=1))) 
WHERE 
AVP_KEY NOT IN 
(SELECT DISTINCT AVP_KEY FROM STG_IT_ATTRIBUTE PARTITION(STG_IT_ATTRIBUTE2460785) WHERE JOB_LOG_ID=2460785 AND CLIENT_ID=355); 
+0

編輯您的問題,並提供樣本數據和期望的結果。 –

+0

「獨特價值」是什麼意思?設置理論操作'MINUS'可能不是正確的工具,但它取決於你真正想做的事情。 – mathguy

+0

這意味着像SELECT AVP_KEY FROM AVP_KEY WHERE AVP_KEY在(SELECT DISTINCT NEW_AVP_KEY FROM GTT_STG_ITEM_ATTR_AVP WHERE ATTRIBUTE_GROUP_ID IN(SELECT ATTRIBUTE_GROUP_ID FROM GTT_STG_ITEM_ATTR_AVP WHERE INSERT_TYPE = 2 MINUS SELECT ATTRIBUTE_GROUP_ID FROM GTT_STG_ITEM_ATTR_AVP WHERE INSERT_TYPE = 1))返回箱1,2,3和SELECT DISTINCT AVP_KEY FROM STG_IT_ATTRIBUTE PARTITION(STG_IT_ATTRIBUTE2460785)WHERE JOB_LOG_ID = 2460785 AND CLIENT_ID = 355返回我1,2,3,4我需要4作爲輸出 –

回答

0

嘗試獲得獨特的價值觀與

SELECT distinct AVP_KEY from (SELECT AVP_KEY FROM AVP_KEY WHERE AVP_KEY IN (SELECT NEW_AVP_KEY FROM GTT_STG_ITEM_ATTR_AVP WHERE ATTRIBUTE_GROUP_ID IN (SELECT ATTRIBUTE_GROUP_ID FROM GTT_STG_ITEM_ATTR_AVP WHERE INSERT_TYPE=2 MINUS SELECT ATTRIBUTE_GROUP_ID FROM GTT_STG_ITEM_ATTR_AVP WHERE INSERT_TYPE=1))) WHERE AVP_KEY NOT IN (SELECT AVP_KEY FROM STG_IT_ATTRIBUTE PARTITION(STG_IT_ATTRIBUTE2460785) WHERE JOB_LOG_ID=2460785 AND CLIENT_ID =355); 

修改代碼得到唯一值======== ================================================== ==============

+0

非常感謝! –