MS Access SQL 语句

发布于 2024-12-08 12:46:35 字数 1600 浏览 0 评论 0原文

情况是这样的,我是当地学区的网络开发人员,我的前任构建了一个自定义应用程序来跟踪孩子的考试成绩。我不是sql专家,所以我尊重大师!

我在 MS Access 中构建了以下表格:

  • 评估 - 这是技能表的总体类别(即数学、阅读等)
  • 技能 - 这些是个人测试并按评估 ID 分类
  • 掌握 - 学生分数;当前显示技能 ID

下面是我现在的表格。最后一张桌子就是我想要的。


评估表

asstID      asstName
1           Math
2           Reading
3           Literature

技能表

skillID     skillName   asstID
80          Vocabulary  3
81          Addition    1
82          Grammar     2

掌握表

masteryID   stuID       score       skillID
20          st001       89          82
21          st001       96          81
22          st001       100         80
23          st002       88          81
24          st002       74          80
25          st002       99          82

掌握表 - 我想要它是什么。

masteryID   stuID       score       skillID     asstID
20          st001       89          82          2
21          st001       96          81          1
22          st001       100         80          3
23          st002       88          81          1
24          st002       74          80          3
25          st002       99          82          2

基本上,我有几千名学生需要将 asstID 添加到掌握表中。

我正在寻求创建 SQL 语句的帮助,我可以将其放入 MS Access 中,该语句将显示与当前表中的 SkillID 相对应的 asstID。

感谢任何帮助。

请不要问我们为什么使用 MS Access,这正是他在构建应用程序时使用的

here's the situation, I work as the web dev for a local school district and my predecessor built a custom app to track kids' test scores. I'm no sql expert, so I defer to the masters!

I have the following tables built in MS Access:

  • Assessment - this is the overarching category for the skills table (ie, math, reading, etc)
  • Skills - these are the individual tests and are categorized by assessment ID
  • Mastery - student scores; currently displays the skills ID

Below, are my tables as they are right now. The very last table is what I'd LIKE to have it be.


Assessment Table

asstID      asstName
1           Math
2           Reading
3           Literature

Skills Table

skillID     skillName   asstID
80          Vocabulary  3
81          Addition    1
82          Grammar     2

Mastery Table

masteryID   stuID       score       skillID
20          st001       89          82
21          st001       96          81
22          st001       100         80
23          st002       88          81
24          st002       74          80
25          st002       99          82

Mastery Table - What I want it to be.

masteryID   stuID       score       skillID     asstID
20          st001       89          82          2
21          st001       96          81          1
22          st001       100         80          3
23          st002       88          81          1
24          st002       74          80          3
25          st002       99          82          2

Basically, I have a couple thousand students that need to have the asstID added to the Mastery Table.

I'm looking for help creating a SQL statement I can put into MS Access that will display the asstID that corresponds to the skillID in the current table.

ANY help is appreciated.

Please don't ask why we're using MS Access, that's just what he used when he built the app

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随遇而安 2024-12-15 12:46:35
SELECT Mastery.masteryID, Mastery.stuID, Mastery.score, Mastery.skillID, Skills.asstID
FROM Mastery 
    INNER JOIN Skills 
        ON Mastery.skillID = Skills.skillID;

在查询设计器(QBE 或按示例查询)网格中,您将添加 Mastery 表和 Skills 表,并确保 Mastery.SkillIDSkills 之间存在关系线。技能ID

SELECT Mastery.masteryID, Mastery.stuID, Mastery.score, Mastery.skillID, Skills.asstID
FROM Mastery 
    INNER JOIN Skills 
        ON Mastery.skillID = Skills.skillID;

In the Query designer (QBE or Query-By-Example) grid, you would add the Mastery table and the Skills table and ensure that there was a relationship line between Mastery.SkillID and Skills.SkillID.

雨后彩虹 2024-12-15 12:46:35

怎么样:

SELECT mastery_table.masteryID, 
       mastery_table.stuID, 
       mastery_table.score, 
       mastery_table.skillID, 
       skills_table.asstID
  FROM mastery_table, skills_table
 WHERE mastery_table.skillID=skills_table.skillID

How about:

SELECT mastery_table.masteryID, 
       mastery_table.stuID, 
       mastery_table.score, 
       mastery_table.skillID, 
       skills_table.asstID
  FROM mastery_table, skills_table
 WHERE mastery_table.skillID=skills_table.skillID
红焚 2024-12-15 12:46:35

这就是我最终用来更新 4k+ 行的方法。在运行此命令之前,我在数据库本身中创建了一个名为 asstID 的新列。

解释:
- 循环遍历 tblMastery 和从每一行获取 tblMastery.skillID 的值
- 连接到 tblSkills 和获取 tblSkills.asstID 的值,其中 tblSkills.skillID 与 tblMastery.skillID 匹配
- 使用 tblSkills.asstID 中的匹配值更新 tblMastery.asstID

希望这对某人有帮助。 :)

<%

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:/database.mdb" 

set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT tblMastery.Skill FROM tblMastery;", conn

  do until rs.eof
    skillID = rs.fields("Skill")

set rs1=Server.CreateObject("ADODB.Recordset")
rs1.open "SELECT SkillID, Assesment FROM tblSkills WHERE SkillID='" & skillID & "';", conn

  asstID = rs1.fields("Assesment")

  sql = "UPDATE tblMastery SET asstID='" & asstID & "' WHERE Skill='" & skillID & "';"
  on error resume next
  conn.Execute(sql)

rs.movenext
loop

%>

This is what I ended up using to update my 4k+ rows. Before running this, I created a new column in the DB itself named asstID.

Explanation:
- loop through tblMastery & grab the value of tblMastery.skillID from each row
- connect to tblSkills & grab the value of tblSkills.asstID where the tblSkills.skillID matches tblMastery.skillID
- update tblMastery.asstID with the matching value from tblSkills.asstID

Hope this helps someone. :)

<%

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:/database.mdb" 

set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT tblMastery.Skill FROM tblMastery;", conn

  do until rs.eof
    skillID = rs.fields("Skill")

set rs1=Server.CreateObject("ADODB.Recordset")
rs1.open "SELECT SkillID, Assesment FROM tblSkills WHERE SkillID='" & skillID & "';", conn

  asstID = rs1.fields("Assesment")

  sql = "UPDATE tblMastery SET asstID='" & asstID & "' WHERE Skill='" & skillID & "';"
  on error resume next
  conn.Execute(sql)

rs.movenext
loop

%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文