SQL Tutorial - Window Functions - Ranking
Another fantastic SQL Tutorial brought to you by BeardedDev.
If you are new to working with Window Functions check out this video:
https://youtu.be/H6OTMoXjNiM
T-SQL Querying
https://www.amazon.com/gp/product/0735685045/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0735685045&linkCode=as2&tag=beardeddev05-20&linkId=e93b0f7483b1fa06aca5a3aec4f7764b
T-SQL Fundamentals
https://www.amazon.com/gp/product/150930200X/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=150930200X&linkCode=as2&tag=beardeddev05-20&linkId=70aa2ffa3e84cab66cb964ca1e9cee62
Microsoft SQL Server 2012 High-Performance T-SQL Using Window Functions
https://www.amazon.com/gp/product/0735658366/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0735658366&linkCode=as2&tag=beardeddev05-20&linkId=b88746aea666c9f98da147e70b4491ca
In this video we explore ranking functions available as part of Window Functions:
ROW_NUMBER()
RANK()
DENSE_RANK()
NTILE()
This tutorial shows an example of when to use each ranking function and the differences between them.
Window Functions were first introduced in SQL Server 2005 but further enhancements and support was added in SQL Server 2012.
We look at the OVER clause and PARTITION BY.
Window Functions can only be included within SELECT or ORDER BY clauses.
Functions Available:
Aggregate - COUNT, SUM, MIN, MAX, AVG
Ranking - ROW_NUMBER, RANK, DENSE_RANK, NTILE
Offset - FIRST_VALUE, LAST_VALUE, LEAD, LAG
Statistical - PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DIST
Windows Functions also have FRAMES
ROWS
RANGE
Window Functions are a powerful tool within SQL Server and I am excited to bring more videos and tutorials working with Window Functions in the future.
ROW_NUMBER - unique incrementing integers
RANK - same rank for same values
DENSE_RANK - same rank for same values
NTILE - assigns tile numbers based on number of tiles requested
SQL:
SELECT
Sales_Id
, Sales_Total
, ROW_NUMBER() OVER(ORDER BY Sales_Total DESC) AS rownum
, RANK() OVER(ORDER BY Sales_Total DESC) AS rnk
, DENSE_RANK() OVER(ORDER BY Sales_Total DESC) AS dense
, NTILE(3) OVER(ORDER BY Sales_Total DESC) AS ntle
FROM dbo.Sales_2
SELECT
Sales_Id
, NTILE(10) OVER(ORDER BY Sales_Total DESC) AS ntle
FROM dbo.Sales_2
Видео SQL Tutorial - Window Functions - Ranking канала BeardedDev
If you are new to working with Window Functions check out this video:
https://youtu.be/H6OTMoXjNiM
T-SQL Querying
https://www.amazon.com/gp/product/0735685045/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0735685045&linkCode=as2&tag=beardeddev05-20&linkId=e93b0f7483b1fa06aca5a3aec4f7764b
T-SQL Fundamentals
https://www.amazon.com/gp/product/150930200X/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=150930200X&linkCode=as2&tag=beardeddev05-20&linkId=70aa2ffa3e84cab66cb964ca1e9cee62
Microsoft SQL Server 2012 High-Performance T-SQL Using Window Functions
https://www.amazon.com/gp/product/0735658366/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0735658366&linkCode=as2&tag=beardeddev05-20&linkId=b88746aea666c9f98da147e70b4491ca
In this video we explore ranking functions available as part of Window Functions:
ROW_NUMBER()
RANK()
DENSE_RANK()
NTILE()
This tutorial shows an example of when to use each ranking function and the differences between them.
Window Functions were first introduced in SQL Server 2005 but further enhancements and support was added in SQL Server 2012.
We look at the OVER clause and PARTITION BY.
Window Functions can only be included within SELECT or ORDER BY clauses.
Functions Available:
Aggregate - COUNT, SUM, MIN, MAX, AVG
Ranking - ROW_NUMBER, RANK, DENSE_RANK, NTILE
Offset - FIRST_VALUE, LAST_VALUE, LEAD, LAG
Statistical - PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DIST
Windows Functions also have FRAMES
ROWS
RANGE
Window Functions are a powerful tool within SQL Server and I am excited to bring more videos and tutorials working with Window Functions in the future.
ROW_NUMBER - unique incrementing integers
RANK - same rank for same values
DENSE_RANK - same rank for same values
NTILE - assigns tile numbers based on number of tiles requested
SQL:
SELECT
Sales_Id
, Sales_Total
, ROW_NUMBER() OVER(ORDER BY Sales_Total DESC) AS rownum
, RANK() OVER(ORDER BY Sales_Total DESC) AS rnk
, DENSE_RANK() OVER(ORDER BY Sales_Total DESC) AS dense
, NTILE(3) OVER(ORDER BY Sales_Total DESC) AS ntle
FROM dbo.Sales_2
SELECT
Sales_Id
, NTILE(10) OVER(ORDER BY Sales_Total DESC) AS ntle
FROM dbo.Sales_2
Видео SQL Tutorial - Window Functions - Ranking канала BeardedDev
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![SQL Tutorial - Window Functions - Ranking with Group By](https://i.ytimg.com/vi/PfMznx4sS8U/default.jpg)
![Analytic Functions A Developer’s Best Friend](https://i.ytimg.com/vi/50HOQBA19T4/default.jpg)
![SQL TUTORIAL - CTEs Part 1](https://i.ytimg.com/vi/3QuYuU9OJfA/default.jpg)
![SQL Tutorial - EXISTS](https://i.ytimg.com/vi/smWEhWKVS_Q/default.jpg)
![](https://i.ytimg.com/vi/-xOtI1MxGd4/default.jpg)
![SQL Tutorial - Window Functions](https://i.ytimg.com/vi/H6OTMoXjNiM/default.jpg)
![Expert Level SQL Tutorial](https://i.ytimg.com/vi/C7CPXeEvKN0/default.jpg)
![SQL Tutorial - PIVOT](https://i.ytimg.com/vi/ozy31aJpW-o/default.jpg)
![Ask TOM Office Hours: SQL Analytics and Pattern Matching](https://i.ytimg.com/vi/FL83r25sNXQ/default.jpg)
![SQL Tutorial - Window Functions - Lag and Lead](https://i.ytimg.com/vi/wOCCxRAQ914/default.jpg)
![Part 1 How to find nth highest salary in sql](https://i.ytimg.com/vi/fvPddKyHxpQ/default.jpg)
![SQL Tutorial - Subqueries (Scalar Valued)](https://i.ytimg.com/vi/5c2r97tDAjY/default.jpg)
![Restricting rows with WINDOWING in Oracle SQL](https://i.ytimg.com/vi/nB5ZHRzsHNg/default.jpg)
![How to Use Temporal Tables in SQL Server 2016](https://i.ytimg.com/vi/ZjsH_V5EkSk/default.jpg)
![SQL Rank function](https://i.ytimg.com/vi/lDPABuZKUkg/default.jpg)
![SQL Tutorial - Window Functions - Calculate Running Totals, Averages](https://i.ytimg.com/vi/6S7z2wabJxk/default.jpg)
![SQL Tutorial - UNPIVOT](https://i.ytimg.com/vi/0ERIr8UAK1s/default.jpg)
![Window Functions](https://i.ytimg.com/vi/blHEnrYwySE/default.jpg)
![FIRST_VALUE and LAST_VALUE : Problem Solving using Analytic Functions](https://i.ytimg.com/vi/sMT3Yzjy-00/default.jpg)
![SQL Tutorial - Logical Query Processing](https://i.ytimg.com/vi/sBRfBU5jh18/default.jpg)