简体   繁体   English

获取sql中完成的所有计数总和的正确方法

[英]right way to get sum of all the counts done in sql

This is my query, I want to get how many numbers of phones call received today as one column, so how do I do a sum using count function?这是我的查询,我想将今天收到的电话数量作为一列,那么如何使用计数功能进行求和?

SELECT (uniquecallerID), [Callername]
FROM [dbo].[phonedatabase] (nolock)
WHERE calltime BETWEEN '2020-08-23' AND '2020-08-24'
-- GROUP BY whatever

If I do a sum, that would just return the total sum?如果我做一个总和,那只会返回总和? how do I return the total numbers of all calls received today, I would do count uniquecallerID and then put them into sum.我如何返回今天收到的所有电话的总数,我会计算uniquecallerID然后把它们加起来。 How do I do that?我怎么做?

Sample data:样本数据:

UniqueID    callername
----------------------
2619        Jack
2358        Travie
2359        Travis S

Are you looking for count(distinct) ?您在寻找count(distinct)吗? Assuming that uniqueCallerID identifies what you want to count:假设uniqueCallerID标识您要计数的内容:

select  count(distinct uniquecallerID)
from [dbo].[phonedatabase] (nolock)
where calltime >= '2020-08-23' and
      calltime < '2020-08-24'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM