基本上我做了查询而且没有用 'Msg 156,Level 15,State 1,Line 2 关键字'FROM''
附近的语法不正确SELECT COUNT(*)
FROM
(
SELECT Group_ID, count(ID)
FROM dbo.S1_Users
WHERE Service_Plan = 'Multi User Foreign (B)'
GROUP BY Group_ID
HAVING count(ID) = 1
)
我知道修复很简单,我搜索了谷歌但未能找到合适的
任何机构都可以解释一下吗?
答案 0 :(得分:5)
您需要命名虚拟表并从内部查询
中命名count(ID)
列
SELECT COUNT(*)
FROM
(
SELECT Group_ID, count(ID) as ID_Count
FROM dbo.S1_Users
WHERE Service_Plan = 'Multi User Foreign (B)'
GROUP BY Group_ID
HAVING count(ID) = 1
) as A
您也可以完全删除计数,而不是使用它
SELECT COUNT(*)
FROM
(
SELECT Group_ID
FROM dbo.S1_Users
WHERE Service_Plan = 'Multi User Foreign (B)'
GROUP BY Group_ID
HAVING count(ID) = 1
) as A
答案 1 :(得分:5)
试试这样:
SELECT COUNT(*)
FROM
(
SELECT Group_ID, count(ID) As cnt
FROM dbo.S1_Users
WHERE Service_Plan = 'Multi User Foreign (B)'
GROUP BY Group_ID
HAVING count(ID) = 1
) A