我想首先计算列:作为每列的实例总数,第二次计算基于条件的实例总数。
我正在使用它:
SELECT
group_name,
Definition_Range,
COUNT([group_name]) AS Number_of_Clients
FROM
[Computer Status]
WHERE
Definition_Range = ' 0-10 Days'
GROUP BY
group_name,
(SELECT COUNT([group_name]) AS Total_Clients
FROM [Computer Status]
GROUP BY group_name)
答案 0 :(得分:0)
以下查询没有任何意义
SELECT COUNT([group_name]) AS Total_Clients
FROM [Computer Status]
GROUP BY group_name
它返回与主查询中写入的Number_of_Clients
相同的内容。
因为您正在group by
进行group_name
。
以下是完美查询
SELECT
group_name,
Definition_Range,
COUNT([group_name]) AS Number_of_Clients
FROM
[Computer Status]
WHERE
Definition_Range = ' 0-10 Days'
GROUP BY
group_name,Definition_Range