Created
February 22, 2021 18:37
-
-
Save geobabbler/91471231742dccfb9ce97f1bb28dec0d to your computer and use it in GitHub Desktop.
SQL sample for blog post - 22 Feb 2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH data AS ( | |
SELECT name, loc, resource_id, wkt, capture_date, (LAG(capture_date) OVER (PARTITION BY resource_id ORDER BY capture_date ASC)) AS prev_date, | |
(LAG(wkt) OVER (PARTITION BY resource_id ORDER BY capture_date ASC)) AS prev_loc | |
FROM | |
(SELECT name, resource_id, loc, st_astext(loc) as wkt, capture_date FROM `my_project.my_dataset.geo_sample` | |
order by capture_date desc) q | |
ORDER BY capture_date | |
) | |
SELECT name, resource_id, loc, capture_date FROM data | |
WHERE | |
wkt<>prev_loc | |
ORDER BY capture_date desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment