我正在尝试获取不删除或更新记录的表中的活动用户数,而是将它添加到表中并假定最后一项是最有效的。但是,对于历史数量,我需要每天的活动次数。如何选择给定日期的最后一个条目
具有下列数据:
--------------------------------------
id | user_id | type | date
--------------------------------------
1 sam New 2017-10-10
2 john New 2017-10-12
3 sam Change 2017-10-14
4 sam Cancel 2017-10-15
我需要能够来算,很多“活动”用户我怎么过的日期。
---------------------
Date | Active
---------------------
...
2017-10-08 0 <-- Prior there were none
2017-10-09 0
2017-10-10 1
2017-10-11 1 <-- Fill-in dates
2017-10-12 2 <-- Cumulative adding
2017-10-13 2
2017-10-14 2 <-- A change is irrelevant
2017-10-15 1 <-- A Cancel should decrease the count
我有一个calendar_table并尝试了各种建议,但似乎无法得到它的权利:如我所期望得到的东西。
请参阅https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a -very-simple-sql-query – Strawberry
给我们一个出发点。告诉我们你试过的东西。 –