Order records based on value

Michael M.M. D'Angelo 156 Reputation points
2023-08-27T01:21:44.4833333+00:00

I have a table with data as below

Script:

CREATE TABLE [dbo].[ClassScore](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[StudentId] [int] NOT NULL,
	[SubjectId] [int] NOT NULL,
	[ClassScore] [decimal](38, 6) NULL,
 CONSTRAINT [PK_ClassScore] 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 IDENTITY_INSERT [dbo].[ClassScore] ON 
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (1, 3071, 2007, CAST(83.099960 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (2, 3068, 2007, CAST(60.599990 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (3, 3072, 2007, CAST(83.099960 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (4, 3073, 2007, CAST(63.659980 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (5, 3071, 2008, CAST(88.428490 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (6, 3068, 2008, CAST(56.999970 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (7, 3072, 2008, CAST(79.571420 AS Decimal(38, 6)))
GO
INSERT [dbo].[ClassScore] ([Id], [StudentId], [SubjectId], [ClassScore]) VALUES (8, 3073, 2008, CAST(54.714200 AS Decimal(38, 6)))
GO
SET IDENTITY_INSERT [dbo].[ClassScore] OFF
GO

User's image

I want to get the position of each student per subject as below using SQL query

User's image

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
10,970 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful