Advertisement
Guest User

Untitled

a guest
Sep 8th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1.  
  2. WITH t AS (
  3. SELECT min(a.timestamp_intersecting_date) d1, min(b.timestamp_intersecting_date) d2,
  4. a."DID",
  5. max(a.timestamp_intersecting_max) t1, min(b.timestamp_intersecting_min) t2,
  6. max(a.id) as a_id, min(b.id) AS b_id,
  7. RANK () OVER (
  8. PARTITION BY a.timestamp_intersecting_date
  9. ORDER BY a.timestamp_intersecting_max DESC
  10. ) timestamp_d1_rank ,
  11. RANK () OVER (
  12. PARTITION BY b.timestamp_intersecting_date
  13. ORDER BY b.timestamp_intersecting_max ASC
  14. ) timestamp_d2_rank
  15. FROM
  16. location_signals_centroids_calculated_daily_excluding_orphans a
  17. INNER JOIN location_signals_centroids_calculated_daily_excluding_orphans b ON (a."DID" = b."DID")
  18. WHERE (b.timestamp_intersecting_date = a.timestamp_intersecting_date + INTERVAL '1 DAY')
  19. AND a."DID" = b."DID"
  20. GROUP BY a."DID"
  21. )
  22. SELECT *, c.coords_centroid AS coords_centroid_min ,d.coords_centroid AS coords_centroid_max
  23. FROM t
  24. INNER JOIN location_signals_centroids_calculated_daily_excluding_orphans c ON (c.id = t.a_id)
  25. INNER JOIN location_signals_centroids_calculated_daily_excluding_orphans d ON (d.id = t.b_id)
  26. WHERE timestamp_d1_rank = 1
  27. AND timestamp_d2_rank = 1
  28. ORDER BY "DID"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement