Skip to content

Instantly share code, notes, and snippets.

@kovid-r
Created May 17, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovid-r/b3c9c3fcb65be6cc853cf83dbec7550e to your computer and use it in GitHub Desktop.
Save kovid-r/b3c9c3fcb65be6cc853cf83dbec7550e to your computer and use it in GitHub Desktop.
LAST_VALUE doesn't work without specifying windows
select distinct p.name,
first_value(s.name) over (partition by p.id order by s.gm desc, s.radius desc) biggest_satellite,
last_value(s.name) over (partition by p.id order by s.gm desc, s.radius desc) smallest_satellite
from devstronomy.planet as p
left join devstronomy.satellite as s
on p.id = s.planet_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment