Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQLServer中根据考试结果生成成绩表_Sql_Sql Server_Sql Server 2008 R2 - Fatal编程技术网

如何在SQLServer中根据考试结果生成成绩表

如何在SQLServer中根据考试结果生成成绩表,sql,sql-server,sql-server-2008-r2,Sql,Sql Server,Sql Server 2008 R2,我正在使用SQLServer2008R2。我的数据库中有一个名为tstResult的表 AI SubID StudID StudName TotalMarks ObtainedMarks -------------------------------------------------------- 1 | 1 | 1 | Jakir | 100 | 90 2 | 1 | 2 | Rubel | 100 |

我正在使用SQLServer2008R2。我的数据库中有一个名为
tstResult
的表

 AI  SubID  StudID  StudName  TotalMarks  ObtainedMarks
--------------------------------------------------------
 1  |   1  |   1  |  Jakir   |    100    |    90
 2  |   1  |   2  |  Rubel   |    100    |    75
 3  |   1  |   3  |  Ruhul   |    100    |    82
 4  |   1  |   4  |  Beauty  |    100    |    82
 5  |   1  |   5  |  Bulbul  |    100    |    96
 6  |   1  |   6  |  Ripon   |    100    |    82
 7  |   1  |   7  |  Aador   |    100    |    76
 8  |   1  |   8  |  Jibon   |    100    |    80
 9  |   1  |   9  |  Rahaat  |    100    |    82
现在我需要一个SELECT查询,它根据获得的分数生成一个优点列表。在本次查询中,获得的分数“96”将在成绩表中排名靠前,所有“82”的分数将依次排列在成绩表中。大概是这样的:

  StudID  StudName  TotalMarks  ObtainedMarks Merit List
 ----------------------------------------------------------
 |   5  |  Bulbul  |    100    |     96     |   1
 |   1  |  Jakir   |    100    |     90     |   2
 |   9  |  Rahaat  |    100    |     82     |   3
 |   3  |  Ruhul   |    100    |     82     |   3
 |   4  |  Beauty  |    100    |     82     |   3
 |   6  |  Ripon   |    100    |     82     |   3
 |   8  |  Jibon   |    100    |     80     |   4
 |   7  |  Aador   |    100    |     76     |   5
 |   2  |  Rubel   |    100    |     75     |   6

您需要使用

为什么82会在绩效表中获得相同的职位?基于什么?
select columns from tstResult order by ObtainedMarks desc
;with cte as
(
select *, dense_rank() over (order by ObtainedMarks desc) as Merit_List
from tstResult
)

select * from cte order by Merit_List desc