Summchpt 2
Summchpt 2
Michel Semaan
Data Scientist
The four functions
Relative
LAG(column, n) returns column 's value at the row n rows before the current row
LEAD(column, n) returns column 's value at the row n rows after the current row
Absolute
FIRST_VALUE(column) returns the first value in the table or partition
Michel Semaan
Data Scientist
The ranking functions
ROW_NUMBER() always assigns unique numbers, even if two rows' values are the same
RANK() assigns the same number to rows with identical values, skipping over the next
numbers in such cases
DENSE_RANK() also assigns the same number to rows with identical values, but doesn't skip over
the next numbers
ROW_NUMBER and RANK will have the same DENSE_RANK 's last rank is the count of
unique values being ranked
last rank, the count of rows
Michel Semaan
Data Scientist
What is paging?
Paging: Splitting data into (approximately) equal chunks
Uses
Many APIs return data in "pages" to reduce data being sent
Separating data into quartiles or thirds (top middle 33%, and bottom thirds) to judge
performance
Enter NTILE
SELECT | Discipline |
DISTINCT Discipline |--------------------- |
FROM Summer_Medals; | Wrestling Freestyle |
| Archery |
| Baseball |
Split the data into 15 approx. equally sized | Lacrosse |
pages | Judo |
| Athletics |
67/15 ≃ 4, so each each page will contain | ... |
SELECT
Third,
ROUND(AVG(Medals), 2) AS Avg_Medals
FROM Thirds
GROUP BY Third
ORDER BY Third ASC;