【发布时间】:2022-11-09 11:00:12
【问题描述】:
Let's say that one has a pair of tables:
users
| user_id | |
|---|---|
| 1 | email1@test.com |
| 2 | email2@test.com |
| ... | ... |
logins
| login_id | user_id | date_login |
|---|---|---|
| 1 | 1 | 2038-01-19 03:14:07 |
| 2 | 1 | 2038-01-19 03:14:08 |
| 3 | 2 | 2038-01-19 03:14:08 |
| ... | ... | ... |
and one wanted to get a list of totals of "active users" for each day of the last year; where "active user" is defined as anyone who had logged in within 30 days of each date in question.
e.g. result: | date_count | activeuser_count | | -------- | -------------- | | 2038-01-19 | 2345 | | 2038-01-20 | 3456 | | 2038-01-21 | 4321 | | ... | ... |
How would one do this most efficiently / with the fewest number of queries?
标签: mysql