Mysql: All users with no activity in last X days -
ok, drawing blank here, , searching not successful.
user table: id, name, email activity table: id, timestamp, user_idmany users, lots of activity, long time ago, none @ all. want user id's no activity in lastly 30 days (or indeed, none @ all). user timestamp exists in lastly 30 days omitted result.
bonus question, rewarded unicorn tears: how alter query update matching user rows, setting column aged=1
you can calculate 30 days using interval
plus or minus operator: curdate() - interval 30 day
.
select user.id user left bring together activity on user.id = activity.user_id grouping user.id having max(activity.timestamp) < curdate() - interval 30 day or max(activity.timestamp) null
the max(activity.timestamp) null
should take care of users have no activity.
mysql android-activity
No comments:
Post a Comment