如何在mssql中获取日期列的总和 [英] how to get sum of column datewise in mssql

查看:92
本文介绍了如何在mssql中获取日期列的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有桌子像



Id查看日期

1 10 2016-01-04 03:33:09.813

2 45 2016-01-04 03:34:09.813

3 100 2016-01-04 03:34:09.813

4 70 2016-01- 05 04:36:09.813

5 19 2016-01-05 03:33:09.813

6 56 2016-01-06 02:33:09.813



现在我需要查看从今天开始的30天以及列日期和Viewcount的查看次数。



来自上表详情i将获得3月4日,5日和6日的3条记录,查看次数为155,89和56.

I have table like

Id View Date
1 10 2016-01-04 03:33:09.813
2 45 2016-01-04 03:34:09.813
3 100 2016-01-04 03:34:09.813
4 70 2016-01-05 04:36:09.813
5 19 2016-01-05 03:33:09.813
6 56 2016-01-06 02:33:09.813

Now I need view count of previous 30 day from today with column date and Viewcount.

from above table details i will get 3 records of 4th, 5th and 6th january with view count 155, 89 and 56.

推荐答案

select sum(ViewCount), cast(ViewDate as date) from [dbo].[Table] where ViewDate>DATEADD(day,-30,getdate()) 
group by cast(ViewDate as date)


这篇关于如何在mssql中获取日期列的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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