【发布时间】:2015-07-30 18:39:07
【问题描述】:
我有以下疑问:
select c2.Responsible, c.deliveryname,
case..... --conditions here
end as 'PortStatus'
from table p
join table c
on p.OwnerContactID = c.ContactID
join table c2
on c.ContactID = c2.ContactID
where p.PortfolioStatus <>''
and c2.responsible <> ''
group by c.deliveryname, p.PortfolioStatus, c2.responsible
给出:
负责的 DeliveryName PortStatus
John Doe Peter Smith DI
John Doe Peter Smith EE
John Doe Peter Smith hy
John Doe Peter Smith pw
John Doe Bob Lee pw
John Doe Bob Lee pw
John Doe Bob Lee ss
我想用计数(不同)修改我的查询,以便我可以看到 每个 Deliveryname 我有多少个唯一的 PortStatus。
我怎样才能让它给我看这个:
负责的 DeliveryName 唯一端口状态
John Doe 彼得·史密斯 4
John Doe Bob Lee 2
【问题讨论】:
-
似乎您已经知道 COUNT (DISTINCT),那么当您尝试它时发生了什么?你收到错误了吗?
-
我得到 4 个而不是 (4)