I have a table with 3 columns: expense, client_id, date. The date has record of clients expense for half a year for each day. Some clients spend many each day, but some not. The expendure ranging from zero to few hundreds. I want to group/count active client, which spend over 50 dollars each day, and calculate how much clients was active between 0-30 days, 30-60 days, 60-90 days, 90-120 days, 120-150 days, 150+. I mean if client spend at least 50 dollars each day along 40 days, i add him to 30-60 days column. client id appears only once each day.
expense | client_id | date |
---|---|---|
20 | 1 | 01/01/2000 |
60 | 2 | 01/01/2020 |
70 | 3 | 01/02/2020 |
the result should be like that
0-30 days | 30-60 days | 60-90 days | 90-120 days |
---|---|---|---|
9 | 3 | 12 | 20 |
the values are count of active clients Thank you a lot