Click here to Skip to main content
14,237,421 members
Rate this:
Please Sign up or sign in to vote.
See more:
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.
Updated 6-Jan-16 22:18pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

select sum(ViewCount), cast(ViewDate as date) from [dbo].[Table] where ViewDate>DATEADD(day,-30,getdate()) 
group by cast(ViewDate as date)
CHill60 21-Mar-16 4:20am
So you found the solution only 7 minutes after posting the question? Why bother posting the question in the first place?
You appear to be posting questions just so you can accept your own solutions - this is frowned upon and can lead to abuse reports. It's also very rude if another member has spent their time trying to help you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100