Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 6-Jan-16 22:18pm
v2

1 solution

SQL
select sum(ViewCount), cast(ViewDate as date) from [dbo].[Table] where ViewDate>DATEADD(day,-30,getdate()) 
group by cast(ViewDate as date)
 
Share this answer
 
v2
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900