Above history table captures time and zones where a tag is present at the moment. I want to find out when a tag enters or exits a zone. tried with
more_data as (
select tag_id,
update_time,
zone_ids as current_zones,
lag(zone_ids, 1) over (partition by tag_id order by update_time asc) as prev_zones
from tag_hist
order by update_time asc
)
select *
from more_data
order by tag_id, update_time asc;
Now I want to compare current and prev zones to identify entered/exited zones
with entered zones = current_zones - prev_zones
with exited zones = prev_zones - current_zones


