Rank functions

The different types of rank functions are as follows:

  • RANK(): Rank of the current row within its partition, with gaps

Rank function syntax: The syntax for the ‘rank’ function is as follows:

  • RANK() OVER ( PARTITION BY <expression>[{,<expression>…}] ORDER BY <expression> [ASC|DESC], [{,<expression>…}] )

Order of SQL statements: The order in which the various SQL statements appear in a query is as follows:

  1. SELECT

Lead and lag functions: These functions are used to compare a row value with the next or the previous row value. The syntax for the ‘lead’ function is as follows:

  • LEAD(expr[, offset[, default]]) OVER (Window_specification | Window_name)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TechGuy

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer