我有一些疑问:
select disconnect_reason as disconnectReason, disconnect_cause, count(*) as callsCount
from calls group by disconnect_reason, disconnect_cause
我如何才能获得callCount = 1的项目
如何在没有having
的情况下获得它?
答案 0 :(得分:4)
总是可以使用Having
子句来过滤组,但如果你想要另一种方式,那么试试这样的事情
select * from
(
select disconnect_reason as disconnectReason, disconnect_cause, count(*) as callsCount
from calls group by disconnect_reason, disconnect_cause
) A
Where callsCount = 1
答案 1 :(得分:1)
尝试使用 CTE 对于 MS SQL SERVER
with cte
as
(
select disconnect_reason as disconnectReason, disconnect_cause, count(*) as callsCount
from calls group by disconnect_reason, disconnect_cause
)
select * from cte where callsCount >0
答案 2 :(得分:1)
select *
from
(
select disconnect_reason as disconnectReason, disconnect_cause, count(*) as callsCount
from calls group by disconnect_reason, disconnect_cause
)base
where callsCount = 1