Akash sharma
Akash sharma

Reputation: 295

how to count all values in a particular column in within date range according to date

I have one table having column :

ID| rect_id| vieweed_user_id| view_count|view_date
1 | 1      | 1              | 1         |2017-03-07 10:54:21
2 | 1      | 2              | 1         |2017-03-08 01:00:45
3 | 1      | 3              | 1         |2017-03-08 12:54:12

I want to find count for all view_count values according to view_date,for example

view_date  | view_count
2017-03-08 |    2
2017-03-07 |    1

but my problem is I want to find all counted view_count values between a specified date range for example

from 2016-03-08 to 2017-03-08

Upvotes: 0

Views: 45

Answers (2)

Dave
Dave

Reputation: 290

try this.

SELECT view_date, sum(view_count) as total_count FROM TABLE_NAME WHERE view_date >= '2016-03-08' AND view_date <= '2017-03-08' group by view_date

Upvotes: 2

imsome1
imsome1

Reputation: 1192

You need to filter between dates and group by date to get the output you need

select view_date,sum(view_count) from TABLE_NAME where view_date between ('2016-03-08' and '2017-03-08') group by view_date

Upvotes: 0

Related Questions