SQL Server query sample using rank/dense_rank


/ Published in: SQL
Save to your folder(s)

SQL Server query sample using rank/dense_rank


Copy this code and paste it in your HTML
  1. USE [AdventureWorks2016CTP3]
  2.  
  3. SELECT
  4. [Sales].[SalesOrderHeader].[CustomerID],
  5. COUNT([SalesOrderID]) AS OrdersCount,
  6. DENSE_RANK() OVER (ORDER BY COUNT([SalesOrderID]) DESC) AS Rank
  7.  
  8. FROM
  9. [Sales].[SalesOrderHeader]
  10.  
  11. GROUP BY
  12. [Sales].[SalesOrderHeader].[CustomerID]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.