Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如果没有“have”,如何按“count(*)`过滤INTEM?_Sql - Fatal编程技术网

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没有具体说明他的身份。