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   

誰かがこれを修正する方法を教えてもらえますか? 出力が 2 番目のランクをスキップしました

注:Rank値はテーブルに保存されません。

4

1 に答える 1

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;
于 2013-08-27T15:16:45.817 に答える