Skip to content

Instantly share code, notes, and snippets.

@fithisux
Last active January 21, 2026 15:14
Show Gist options
  • Select an option

  • Save fithisux/60f4bff3509e19a350af2331a2999b46 to your computer and use it in GitHub Desktop.

Select an option

Save fithisux/60f4bff3509e19a350af2331a2999b46 to your computer and use it in GitHub Desktop.
Final query
with annotated_data as (
SELECT
*,
to_json(struct(* except (object_id, sample_id))) as xxx,
lag(to_json(struct(* except (object_id, sample_id)))) over tracked_id_timeline as prev_xxx,
row_number() over tracked_id_timeline as rr
FROM
VALUES ('A1', 2, 1, 5), ('A1', 1, 1, 5), ('A2', 3, 3, 7), ('A1', 3, 2, 6) tab
(object_id, sample_id, feature_1, feature_2)
WINDOW tracked_id_timeline as (PARTITION BY object_id ORDER BY sample_id)
)
select
* except (rr, prev_xxx, xxx)
from
annotated_data
where
rr = 1 or xxx != prev_xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment