我有一个列有列:
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
我想根据view_date找到所有view_count值的计数,例如
view_date | view_count
2017-03-08 | 2
2017-03-07 | 1
但我的问题是我想在指定的日期范围之间找到所有已计算的view_count值,例如
2016-03-08至2017-03-08
答案 0 :(得分:2)
试试这个。
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
答案 1 :(得分:0)
您需要在日期和日期之间进行过滤,以获得所需的输出
select view_date,sum(view_count) from TABLE_NAME where view_date between ('2016-03-08' and '2017-03-08') group by view_date