Загрузка страницы

SQL Tutorial - Window Functions - Ranking with Group By

Another fantastic SQL Tutorial brought to you by BeardedDev.

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

If you are new to working with Windows Functions check out this video: https://youtu.be/H6OTMoXjNiM

If you want to find out more about the Group By clause and working with aggregate functions check out this video: https://youtu.be/TYD6gWP3jBg

If you are interested in finding out more about ranking functions available in SQL Server check out this video: https://youtu.be/xL7BtCT7ix4

In this tutorial we explore ranking functions as part of Window Functions using the Group By clause within SQL Server.

In this example we go through how to rank customers based on the sum of the orders they have placed with us.

The window function example also covers the difference between using Rank and Dense_Rank.

SQL
SELECT
Sales_Cust_Id
, SUM(Sales_Total) AS Total
FROM dbo.Sales_2
GROUP BY Sales_Cust_Id
ORDER BY Total DESC

SELECT
Sales_Cust_Id
, SUM(Sales_Total) AS Total
, RANK() OVER(ORDER BY SUM(Sales_Total) DESC) AS rnk
, DENSE_RANK() OVER(ORDER BY SUM(Sales_Total) DESC) AS dnse
FROM dbo.Sales_2
GROUP BY Sales_Cust_Id
ORDER BY rnk

Видео SQL Tutorial - Window Functions - Ranking with Group By канала BeardedDev
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
10 ноября 2017 г. 10:00:01
00:07:14
Яндекс.Метрика