I have a data which gives idea about user when did the user subscribed to a service, in a city and when it will expire.
It is as below
+------+------------+------------+
| City | Start_Date | End_Date |
+------+------------+------------+
| LA | 2019-06-01 | 2019-06-03 |
| LA | 2019-06-07 | 2019-06-10 |
| LA | 2019-06-09 | 2019-06-11 |
| LA | 2019-06-13 | 2019-06-14 |
| LO | 2019-06-01 | 2019-06-05 |
| LO | 2019-06-04 | 2019-06-05 |
| LO | 2019-06-07 | 2019-06-09 |
| LO | 2019-06-08 | 2019-06-09 |
+------+------------+------------+
I want count of active users for each city for each day at a given date
Output should be somewhat similar to
+------+------------+-------+
| City | Day | Count |
+------+------------+-------+
| LA | 2019-06-01 | 1 |
| LA | 2019-06-02 | 1 |
| LA | 2019-06-03 | 1 |
| LA | 2019-06-04 | 0 |
| LA | 2019-06-05 | 0 |
| LA | 2019-06-06 | 0 |
| LA | 2019-06-07 | 1 |
| LA | 2019-06-08 | 1 |
| LA | 2019-06-09 | 2 |
| LA | 2019-06-10 | 2 |
| LA | 2019-06-11 | 1 |
| LA | 2019-06-12 | 0 |
| LA | 2019-06-13 | 1 |
| LA | 2019-06-14 | 1 |
| LA | 2019-06-15 | 0 |
+------+------------+-------+
The output I have shown is only for City LA
and I also want similar output for every city in the table.
Description of my output
- In
City = LA
onDay = 2019-06-01
there was 1 user with active subscription, similarly forDay = 2019-06-02
. - In
City = LA
onDay = 2019-06-09
there were 2 users with active subscription and so on.
Any help will be appreciated