Rank RowNumber And Dense_Rank Working Explained

USE [tempdb]

GO

Drop TABLE [dbo].[Table_2]

GO

/****** Object:  Table [dbo].[Table_2]    Script Date: 02/06/16 17:51:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Table_2](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Player] [varchar](50) NULL,
[Score] [numeric](18, 3) NULL,
 CONSTRAINT [PK_Table_2] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO



GO

INSERT INTO [dbo].[Table_2]
           ([Player]
           ,[Score])
     VALUES
           ('A',9.9),
  ('B',9.8),
  ('C',9.7),
  ('D',9.6),
  ('E',9.6),
  ('F',9.2)
GO


Select ID,Player,Score,Row_Number() Over (order by Score) as RowNumber,Rank() Over (order by Score) as Rnk,Dense_Rank() Over (order by Score) as DenseRank from table_2


-- RowNumber : Will not Skip number
-- Rank : When Found Same value Value or Ties it will have same number for both and will Skip the Number
-- Dense_Rank : when Found Same Value Or Ties it will have numer for both but next number will not Skip

Comments

Popular posts from this blog

Rebuild Index

Exclude property of Class Object from Serialization

Multiple Connection from Config File