04pallav
9/13/2017 - 9:52 PM

RANK DENSE RANK

RANK DENSE RANK


Select RANK() over( order by col1) colnam1
Select Dense_rank() over(order by col1) colnam2


Select RANK() over( partition by col2 order by col1) colnam1
Select Dense_rank() over(partition by col2 order by col1) colnam2


Difference between rank, denserank, rowno
RANK() returns 1,1,3,4
DENSE_RANK() returns 1,1,2,3
ROW_NUMBER() returns 1,2,3,4


NTILE() OVER( partition by col2 order by col1 desc)

LEAD(col1) over (partition by col2 order by col1 desc)
LEAD(col1,2,-1) over (partition by col2 order by col1 desc)

##leading by 2 rows. default value -1

FIRST_VALUE(zipcode) over(order by order_date)


sum(salary) over (partition by gender)

## will have effect of grouping by

sum(salary) over(order by salary desc)
## will create running total