gpt4 book ai didi

sql-server - 计算选择查询返回的行数

转载 作者:行者123 更新时间:2023-12-01 19:03:50 28 4
gpt4 key购买 nike

我需要计算以下查询返回的行数。

select m.Company_id
from Monitor as m
inner join Monitor_Request as mr on mr.Company_ID=m.Company_id
group by m.Company_id
having COUNT(m.Monitor_id)>=5

我尝试过以下

select COUNT(*) from
(
select m.Company_id
from Monitor as m
inner join Monitor_Request as mr on mr.Company_ID=m.Company_id
group by m.Company_id
having COUNT(m.Monitor_id)>=5)

它在查询分析器中给出一条错误消息,内容如下:

Msg 102, Level 15, State 1, Line 7 Incorrect syntax near ')'.

最佳答案

SQL Server 要求您 SELECT FROMJOIN 的子查询具有别名。

向子查询添加别名(在本例中为 x):

select COUNT(*) from
(
select m.Company_id
from Monitor as m
inner join Monitor_Request as mr on mr.Company_ID=m.Company_id
group by m.Company_id
having COUNT(m.Monitor_id)>=5) x

关于sql-server - 计算选择查询返回的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9945755/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com