This question evaluates a candidate's ability to derive current entity state from a prior snapshot and a sequence of actions, testing competencies in SQL querying, data aggregation, and state inference within the Data Manipulation (SQL/Python) domain.
You are given two tables about members' push-notification settings.
Table 1: status_snapshot
member_id
INT
status
STRING — either
'on'
or
'off'
This table stores each member's latest known notification setting as of 2020-01-31 23:59:59 UTC.
Table 2: actions
member_id
INT
action_date
DATE — UTC calendar date between
2020-02-01
and
2020-02-29
action
STRING — either
'turn_on'
or
'turn_off'
Assumptions:
actions
is a notification-setting action that occurs after the snapshot in
status_snapshot
.
actions
(for example, new members created after the snapshot date).
Write SQL to return each member's current notification status as of 2020-02-29 23:59:59 UTC.
member_id, current_status
Follow-up:
Suppose actions no longer contains action_date. Under the assumption that every recorded action is a valid state transition from the member's previous state (so contradictory repeated actions such as turn_on when already on do not occur), write SQL or describe how you would infer the final status as of 2020-02-29 using only the snapshot plus the multiset of February actions.