我试图在SQL服务器中执行以下查询但是我收到错误。有人可以解释一下如何计算内部选择语句吗?
SELECT COUNT(*) from
(Select ID,
COUNT(ID)
FROM [Testing].[dbo].[Bench] group by ID having COUNT(*) =5);
答案 0 :(得分:8)
我想你错过了第二栏的名字:
SELECT COUNT(*)
FROM (
Select id, COUNT(id) count_of_id
FROM [Testing].[dbo].[Bench]
GROUP BY id
HAVING COUNT(*) =5
);
答案 1 :(得分:5)
尝试以下代码:
SELECT COUNT(*) from
(Select ID,
COUNT(ID) as cnt
FROM [Testing].[dbo].[Bench] group by ID having COUNT(*) =5) tbl;