ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Set Group wise rank using Rank function in SQL Server<p>Hi <a class="username" rel="smile"> smile</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DECLARE @tblSetMarks AS TABLE(AdmissionNo VARCHAR(10),SubjectID VARCHAR(MAX),Obtain INT, Max INT) INSERT INTO @tblSetMarks VALUES(&#39;R-000501&#39;,&#39;128&#39;,34,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000502&#39;,&#39;128&#39;,43 ,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000503&#39;,&#39;128&#39;,34,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000504&#39;,&#39;128&#39;,5 ,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000505&#39;,&#39;128&#39;,32,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000501&#39;,&#39;129&#39;,21,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000502&#39;,&#39;129&#39;,25,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000503&#39;,&#39;129&#39;,45,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000504&#39;,&#39;129&#39;,43,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000505&#39;,&#39;129&#39;,32,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000501&#39;,&#39;130&#39;,44,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000502&#39;,&#39;130&#39;,34,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000503&#39;,&#39;130&#39;,23,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000504&#39;,&#39;130&#39;,23,50) INSERT INTO @tblSetMarks VALUES(&#39;R-000505&#39;,&#39;130&#39;,47,50) SELECT AdmissionNo,SubjectID,Max, Obtain ,rank() over(partition BY SubjectID order by Obtain DESC)&nbsp; AS Rank FROM @tblSetMarks ORDER BY AdmissionNo,SubjectID</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/134612/Set-Group-wise-rank-using-Rank-function-in-SQL-Server/https://www.aspforums.net:443/Threads/134612/Set-Group-wise-rank-using-Rank-function-in-SQL-Server/Tue, 27 Aug 2019 08:07:13 GMT