2014-09-12 109 views
2

我有兩個名爲FICA11,FICA7的表。現在FICA7是客戶的舊記錄,而fica11是新記錄,我們稱之爲維修記錄。比較兩個表(其中一個表有另一個沒有)

我需要按月基地做的是看到FICA11這不是在fica7表來什麼新的文檔(維修記錄)

樣本數據FICA7

ID Number Document_Type 
2456525425625,other 
2456525425625,POA 
2456525425625,POA 
2456522456585,other 
2456522456585,id 
1245879566554,other 
1245879566554,ID 

示例數據FICA11

ID Number Document_Type 
    2456525425625,other 
    2456525425625,id 
    2456525425625,POA 
    2456522456585,other 
    2456522456585,id 
    1245879566554,poa 
    1245879566554,ID 

現在我必須能夠看到的是有多少新的ID,我們現在從FICA11有,我們沒有在FICA7

有從上面的例子。

New ID 1   
New POA 1 
New Other 1 

回答

3

使用NOT EXISTS + Group By + Count:使用左外

SELECT Document_Type, Count(*) AS [Count] 
FROM FICA11 f11 
WHERE NOT EXISTS 
(
    SELECT 1 FROM FICA7 f7 
    WHERE f11.Number = f7.Number 
     AND f11.Document_Type = f7.Document_Type 
) 
GROUP BY Document_Type 
+0

這是偉大的太感謝你了 – user3906930 2014-09-12 14:08:39

0

備選: -

SELECT F11.Document_Type, count(f11.document_type) - Count(f7.document_type) AS Count 
FROM FICA11 f11 LEFT OUTER JOIN FICA7 f7 ON f11.ID_Number = f7.ID_Number AND f11.Document_Type = f7.Document_Type 
GROUP BY f11.Document_type 
相關問題