【问题标题】:Ranking of Student based on their Mark and Average基于分数和平均分的学生排名
【发布时间】:2013-08-26 20:39:29
【问题描述】:

这是我的问题:

  1. 如果学生在任何科目中获得 49 分及以下的分数,他将不会被列入排名。

  2. 各科49分以上的学生按平均分排名

  3. 如果学生的平均分相等,那么他们的排名应该是相等的。

这是我的示例:

Table1                      
Student_ID  Name    Math    English   Science   Average 
   1        Apple    64       49        70      61.00   
   2        Boy      80       79        65      74.67   
   3        Cat      51       78        66      65.00   
   4        Dove     50       76        64      63.33   
   5        Eden     81       88        72      80.33   
   6        Fox      80       79        65      74.67   
   7        Golf     32       88        69      63.00   


Output                      
Student_ID  Name    Math    English   Science   Average    RANK
   1        Apple    64       49        70      61.00   
   2        Boy      80       79        65      74.67        2
   3        Cat      51       78        66      65.00        3
   4        Dove     50       76        64      63.33        4  
   5        Eden     81       88        72      80.33        1
   6        Fox      80       79        65      74.67        2
   7        Golf     32       88        69      63.00   

这是我的查询:

SELECT
    tmain.Student_ID,
    tmain.Name,
    tmain.Math,
    tmain.English,
    tmain.Science,
    tmain.Average,
    IIf(sub.RANK=0, Null, sub.RANK) AS RANK
FROM
    Table1 AS tmain
    LEFT JOIN
    (
        SELECT
            t1.Student_ID,
            t1.Average,
            (
                SELECT Count(*)
                FROM Table1 AS t2
                WHERE
                        t2.Math>49
                    AND t2.English>49
                    AND t2.Science>49
                    AND t2.Average>=t1.Average                    
            ) AS RANK
        FROM Table1 AS t1
        WHERE
                t1.Math>49
            AND t1.English>49
            AND t1.Science>49
    ) AS sub
    ON tmain.Student_ID = sub.Student_ID;

基于查询的输出:

Output                      
Student_ID  Name    Math    English   Science   Average    RANK
   1        Apple    64       49        70      61.00   
   2        Boy      80       79        65      74.67        3
   3        Cat      51       78        66      65.00        4
   4        Dove     50       76        64      63.33        5  
   5        Eden     81       88        72      80.33        1
   6        Fox      80       79        65      74.67        3
   7        Golf     32       88        69      63.00   

谁能帮我解决这个问题,输出跳过了第二名

注意:Rank 值不存储在表中。

【问题讨论】:

  • 您应该尝试解决您在此处发布的问题。你能写一个查询来返回任何数据吗?
  • @user814064 先生,很抱歉没有在我的问题中包含我的查询。我编辑了我的帖子并包含了我的查询及其输出。
  • 你的两个 #3 的每个班级的成绩都相同。你想如何解决这个问题?你想如何确定谁是#2,谁是#3?
  • 我希望 Student_ID 2 和 6 成为第二而不是第三。输出跳过了第二名

标签: ms-access ms-access-2010 ranking


【解决方案1】:

除非我误解了你,否则这会给你你所需要的:

SELECT tblStudents.StudentID, 
  tblStudents.SName, 
  tblStudents.Math, 
  tblStudents.English, 
  tblStudents.Science, 
  tblStudents.AvgScore, 
  tblStudents.Rank
FROM tblStudents
WHERE 
  (((tblStudents.Math)>49) AND 
   ((tblStudents.English)>49) AND 
   ((tblStudents.Science)>49))
ORDER BY tblStudents.AvgScore DESC;

【讨论】:

  • 谢谢你们,但排名没有存储在表格中。
  • 如果您在帖子中添加“编辑”一词然后显示编辑内容,这有助于我的可信度。
猜你喜欢
  • 2020-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 2021-07-18
相关资源
最近更新 更多