When using Group By() for a column, for each unique entry in that column, the aggregate
function is applied
Pay attention, to use Group By, we need to use Aggregate function for rest of the columns
mentioned in the SELECT statement
But what if, we needed to display the whole table, i.e. SELECT * FROM Table_Name, and
along with it, wanted to apply aggregate function
We dont wish to Group By at any column, we wish to display the whole table, and still,
want to make use of Aggregate Function
Here, OVER() comes to our rescue
But what good is that newly created column, if it repeats just 1 value throughout?
Thus, lets create more windows, i.e. lets Partion the window. Assume, we want to create
separate windows for each state, then what we need is a window which has separate Partion for
each State: Partion By(State)
Lag and Lead: These functions allow you to examine the next or previous row, may then
compare this value to the current row
nth_value: Gives the nth-value, after the current row
nth_value will return the nth_value, but if we do not specify a range it will
return null if the current value is less than the nth. If we always want something displayed
we need to specify a range
ntile: ntile(n) divides the group into n equal partitions and denotes which partition
each row is in
Credits: windowfunctions.com