简体   繁体   English

Access 2010:查找具有所选成绩的学生

[英]Access 2010: Find students with select grades

I have just made an Access 2010 database for analyzing students' grades in an exam. 我刚刚制作了一个Access 2010数据库,用于分析考试中的学生成绩。 I was able to get grades for all students right. 我能够为所有学生取得好成绩。 There are six subjects. 有六个科目。 Finding who got A in all six was easy, but what I want to do now is find who got A grade in any five out of six. 找出谁在所有六个中都获得A成绩很容易,但是我现在要做的是找到谁在六个中的任何五个中都获得A成绩。 Similarly, who missed A in any two subjects. 同样,谁在任何两个科目中都错过了A。 Who failed in one subject? 谁在一个学科上不及格? Two subjects? 两个科目? I just couldn't find a way to do it. 我只是找不到办法。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

PS: What I have on my mind is a form with two text or combo boxes where you put Grades in one and Subjects in the other to get the result. PS:我想到的是一个带有两个文本或组合框的表单,您可以在其中放置“成绩”,而在另一个中放置“主题”以获得结果。 For example, you select B in the first and Three in the second to get the list of students who got B grade in any three subjects. 例如,您选择第一项中的B,第二项中的B,以获取在任何三门课程中均获得B级成绩的学生列表。 Only I don't know how it can be done. 只有我不知道该怎么做。

What I did to find students who got A for all subjects: Used A as the criteria in the query. 我如何查找所有科目都获得A的学生:将A用作查询中的条件。

SELECT 
    exam_grade.SNAME, 
    exam_grade.[Language Score], 
    exam_grade.[English Grade], 
    exam_grade.[Language Grade], 
    exam_grade.[Phy Grade], 
    exam_grade.[Chem Grade], 
    exam_grade.[Bio Grade], 
    exam_grade.[Math Grade], 
    exam_grade.DIVISION, 
    exam_grade.Result
FROM exam_grade
WHERE (((exam_grade.[English Grade])="A") 
    AND ((exam_grade.[Language Grade])="A") 
    AND ((exam_grade.[Phy Grade])="A") 
    AND ((exam_grade.[Chem Grade])="A") 
    AND ((exam_grade.[Bio Grade])="A") 
    AND ((exam_grade.[Math Grade])="A"));

As you're storing each subject in its own column (rather than being decomposed into rows) you'll always have to specify every subject in every query. 在将每个主题存储在其自己的列中(而不是分解为行)时,您始终必须在每个查询中指定每个主题。 This does make the queries more conceptually simpler as then it's just a matter of doing boolean logic: 这确实使查询在概念上更加简单,因为这只是做布尔逻辑的问题:

Students who had any 'A' grade: 取得“ A”级成绩的学生:

SELECT 
    exam_grade.SNAME, 
    exam_grade.[Language Score], 
    exam_grade.[English Grade], 
    exam_grade.[Language Grade], 
    exam_grade.[Phy Grade], 
    exam_grade.[Chem Grade], 
    exam_grade.[Bio Grade], 
    exam_grade.[Math Grade], 
    exam_grade.DIVISION, 
    exam_grade.Result
FROM
    exam_grade
WHERE
    exam_grade.[English Grade]  = "A" OR
    exam_grade.[Language Grade] = "A" OR
    exam_grade.[Phy Grade]      = "A" OR
    exam_grade.[Chem Grade]     = "A" OR
    exam_grade.[Bio Grade]      = "A" OR
    exam_grade.[Math Grade]     = "A"

Students failed any subject: 学生未通过任何学科:

....
WHERE
    exam_grade.[English Grade]  = "F" OR
    exam_grade.[Language Grade] = "F" OR
    exam_grade.[Phy Grade]      = "F" OR
    exam_grade.[Chem Grade]     = "F" OR
    exam_grade.[Bio Grade]      = "F" OR
    exam_grade.[Math Grade]     = "F"

...and so on for each query you have. ...,依此类推。

You can simplify this by adopting a decomposed database structure, like so: 您可以通过采用分解的数据库结构来简化此过程,如下所示:

CREATE TABLE Students (
    StudentId bigint PRIMARY KEY IDENTITY(1,1),
    FirstName nvarchar(50),
    LastName nvarchar(50)
)

CREATE TABLE Subjects (
    SubjectId bigint PRIMARY KEY IDENTITY(1,1),
    Name nvarchar(50)
)

CREATE TABLE Results (
    StudentId bigint,
    SubjectId bigint, -- composite key with StudentId, assuming no student can take the same subject twice
    Grade     char(1) -- though storing the numeric score would be more flexible
)

Then to find students that failed any subject (for example) 然后查找未通过任何学科的学生(例如)

SELECT
    Students.FirstName,
    Students.LastName,
    FailedResults.FailedCount
FROM

    (SELECT
        Results.StudentId,
        COUNT(*) As FailedCount
    FROM
        Results
        INNER JOIN Subjects ON Results.SubjectId = Subjects.SubjectId
    WHERE
        Results.Grade = 'F'
    GROUP BY
        Results.StudentId
    ) As FailedResults

    INNER JOIN Students ON FailedResults.StudentId = Students.StudentId

this way you just add rows to the Subjects and Results table without needing to add columns and re-edit your queries. 这样,您只需将行添加到“ SubjectsResults表中,而无需添加列并重新编辑查询。

According to your example and what do you want to do and just following your logic because I think that you have an algorithm for resolve, I can suggest this: 根据您的示例以及您想做什么,并遵循逻辑,因为我认为您有解决问题的算法,因此我建议:

First, you need to put a value for each grade, for example I simplify the grades in three. 首先,您需要为每个年级输入一个值,例如,我将年级简化为三个。

POSIBLE GRADES A,B,C WITH THEIR VALUES 可能的等级A,B,C及其值

  • A = 3 A = 3
  • B = 2 B = 2
  • C = 1 C = 1

Then you need to sum the changed values, like this: 然后,您需要对更改后的值求和,如下所示:

 SELECT * FROM
    (SELECT id_student,
        CONVERT(INT,CASE language_grade
            WHEN 'A' THEN '3' 
            WHEN 'B' THEN '2' 
            WHEN 'C' THEN '1'
        END)
        +
        CONVERT(INT,CASE english_grade
            WHEN 'A' THEN '3' 
            WHEN 'B' THEN '2' 
            WHEN 'C' THEN '1'
        END)
        +
        CONVERT(INT,CASE chem_grade
            WHEN 'A' THEN '3' 
            WHEN 'B' THEN '2' 
            WHEN 'C' THEN '1'
        END) AS RESULT
 FROM test) TB
 WHERE RESULT >= 6

Well, following your form example, you can select 'A' grade in first combobox, Then you put number 2, this mean that you want at least 2 subjects with at least 'A' in grade, if you that you grade 'A' has value of three, you can multiply that value to the number put in the second textbox, and that result is 6, so you can deduce else rigth? 好吧,按照您的表格示例,您可以在第一个组合框中选择“ A”级,然后输入数字2,这意味着如果您要对“ A”级进行评分,则希望至少有2个科目的等级至少为“ A”的值为3,您可以将该值乘以第二个文本框中的数字,结果为6,这样就可以得出其他的正确性? ;). )。 (Dont forget to use equal,greater than or equal, etc, to change your query.) (请不要忘记使用equal,大于或等于等来更改查询。)

PSDT PSDT

I know that this isn't access sintax, but if you can "translate" to access sintax, this will work. 我知道这不是访问sintax,但是如果您可以“翻译”访问sintax,那么它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM