/ Published in: SQL
SQL Server query sample using rank/dense_rank
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
USE [AdventureWorks2016CTP3] SELECT [Sales].[SalesOrderHeader].[CustomerID], COUNT([SalesOrderID]) AS OrdersCount, DENSE_RANK() OVER (ORDER BY COUNT([SalesOrderID]) DESC) AS Rank FROM [Sales].[SalesOrderHeader] GROUP BY [Sales].[SalesOrderHeader].[CustomerID]