我正在尝试在 SQL Server 中执行以下查询,但出现错误。有人可以解释一下如何计算内部选择语句吗?
SELECT COUNT(*) from
(Select ID,
COUNT(ID)
FROM [Testing].[dbo].[Bench] group by ID having COUNT(*) =5);
我正在尝试在 SQL Server 中执行以下查询,但出现错误。有人可以解释一下如何计算内部选择语句吗?
SELECT COUNT(*) from
(Select ID,
COUNT(ID)
FROM [Testing].[dbo].[Bench] group by ID having COUNT(*) =5);
我想您只是错过了第二列的名称:
SELECT COUNT(*)
FROM (
Select id, COUNT(id) count_of_id
FROM [Testing].[dbo].[Bench]
GROUP BY id
HAVING COUNT(*) =5
);
试试下面的代码:
SELECT COUNT(*) from
(Select ID,
COUNT(ID) as cnt
FROM [Testing].[dbo].[Bench] group by ID having COUNT(*) =5) tbl;