2014-02-27 50 views
0

我有一個簡單的查詢,列出具有多個打開的服務作業的客戶端。已修改的SQL查詢不顯示所有結果

select link_to_client, count(call_ref) 'Services' 
from calls 
where call_type='PM' 
and last_event_status not in ('RD','C','X') 
group by link_to_client 
having count(call_ref)>1 

這產生了11的結果。

G838AH/24 2 
G21/311  2 
G328RE/18 29 
G328RE  4 
G849RJ/6 2 
ML110PQ/2 2 
G21/505  2 
G15PR  2 
G21/314  2 
ML60BN/2 2 
G214AE/12 2 

我需要添加另一場來顯示(link_to_contract_header)

select link_to_client, link_to_contract_header, count(call_ref) 'Services' 
from calls 
where call_type='PM' 
and last_event_status not in ('RD','C','X') 
group by link_to_client, link_to_contract_header 
having count(call_ref)>1 

但是當我添加此到查詢我只只有9結果

ML60BN/2 CLYVAL-2-1 2 
G849RJ/6 127-3  2 
G21/505  NGLA-1  2 
G21/311  NGLA-1  2 
G15PR  WOS-1  2 
G214AE/12 NGLA-1  2 
G328RE  CTSP-1  4 
G21/314  NGLA-1  2 
G328RE/18 CTSP-1  29 

所以其中最終我錯了嗎?

回答

0

在2其他線路你有不一樣的link_to_client, link_to_contract_header, 如果按只link_to_client那麼你必須計數> 1,但如果按link_to_client, link_to_contract_header,兩個deletet不具有計數> 1

更新

您可以檢查在2線G838AH/24的link_to_contract_header值(你會發現不同的值)

+0

OK是的,我看到現在。 所以我需要做什麼才能讓它顯示所有11個結果,按照原始的,但新的領域也顯示? – chenks

+0

要顯示11條結果讓你使link_to_contract_header相等,因爲這兩條線不顯示,或者接受這個結果,因爲你不能顯示G838AH/24的link_to_contract_heade,它有兩個不同的值 – Akrem

+0

這是一個窘境,因爲我必須解決人們的數據輸入錯誤! – chenks