Skip to content

Instantly share code, notes, and snippets.

@kovid-r
Created May 17, 2020 14:48
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/d3cc7ef3294417e323bf178f66f05853 to your computer and use it in GitHub Desktop.
Save kovid-r/d3cc7ef3294417e323bf178f66f05853 to your computer and use it in GitHub Desktop.
Basic Window Functions
select p.name,
row_number() over () rn,
rank() over () rnk,
dense_rank() over () dns_rnk,
lead(p.name) over () lead_name,
lag(p.name) over () lag_name,
first_value(p.name) over () fv_name,
last_value(p.name) over () lv_name,
ntile(4) over () quartile,
ntile(5) over () quintile
from devstronomy.planet as p;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment