我有一个简单的查询,列出了具有多个开放服务作业的客户端。
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 :(得分:0)
在另外两行中,你的link_to_client, link_to_contract_header,
不一样
如果您只按link_to_client
分组,那么您的计数>> 1但如果按link_to_client, link_to_contract_header,
分组,则两行删除不计算> 1
<强>更新强>
你可以检查G838AH / 24的2行link_to_contract_header
的值(你会发现不同的值)