2013-08-26 75 views
0

这里是我的问题:排行学生和平均

  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值不存储在表中。

+3

你应该在你解决这里张贴问题的一种尝试。你能写一个查询来返回任何数据吗? – dcaswell

+0

Sir @ user814064对不起,我的问题没有包括我的查询。我编辑了我的文章,并包含了我的查询和输出。 – nine05

+0

你的#3的每个班都有相同的成绩。你想如何解决这个问题?你如何确定谁是#2和谁是#3? –

回答

0

除非我误解你,这会给你你需要的东西:

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; 
+1

谢谢你们,但Rank并不存储在表中。 – nine05

+0

如果您在文章中添加“编辑”一词,然后显示编辑,它将有助于我的信誉。 –