Sql 如果没有“have”,如何按“count(*)`过滤INTEM?
我有一些疑问:Sql 如果没有“have”,如何按“count(*)`过滤INTEM?,sql,Sql,我有一些疑问: select disconnect_reason as disconnectReason, disconnect_cause, count(*) as callsCount from calls group by disconnect_reason, disconnect_cause 如何仅获取callsCount=1的项目。 如果没有having,我如何获得它?您始终可以使用having子句来筛选组,但如果您需要另一种方法,请尝试类似的方法 select * from
select disconnect_reason as disconnectReason, disconnect_cause, count(*) as callsCount
from calls group by disconnect_reason, disconnect_cause
如何仅获取callsCount=1的项目。如果没有
having
,我如何获得它?您始终可以使用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
您始终可以使用
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
尝试将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
尝试将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
使用
have
有什么问题?在where子句中尝试子查询。使用have
有什么问题?在where子句中尝试子查询。并非所有数据库引擎都支持此功能。OP没有指定他的。并非所有数据库引擎都支持此操作。OP没有具体说明他的身份。