如何计算每天的记录数? [英] How to count number of records per day?

查看:141
本文介绍了如何计算每天的记录数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,其结构如下:

I have a table in a with the following structure:

CustID --- DateAdded ---

 396       2012-02-09 
 396       2012-02-09 
 396       2012-02-08 
 396       2012-02-07 
 396       2012-02-07
 396       2012-02-07 
 396       2012-02-06
 396       2012-02-06

我想知道如何计算每天的记录数,在SQL中的最后7天,然后返回一个整数。

I would like to know how I can count the number of records per day, for the last 7 days in SQL and then return this as an integer.

目前我写了以下SQL查询:

At present I have the following SQL query written:

SELECT * 
  FROM Responses
 WHERE DateAdded >= dateadd(day, datediff(day, 0, GetDate()) - 7, 0)

RETURN

但是,这仅返回过去7天的所有条目。如何计算过去7天每天的记录?

However this only returns all entries for the past 7 days. How can I count the records per day for the last 7 days?

推荐答案

select DateAdded, count(CustID)
from Responses
WHERE DateAdded >=dateadd(day,datediff(day,0,GetDate())- 7,0)
GROUP BY DateAdded

这篇关于如何计算每天的记录数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆