我应该如何将 sql 表中的所有行与“主记录”进行比较?使用vb.net?

发布于 2025-01-08 20:37:30 字数 307 浏览 1 评论 0原文

举例来说,这是一个测验,其中不同学生的答案已加载到数据库中。在包含各种学生答案的各种学生条目的表格内部,有一行“masterentry”包含所有正确答案。

我想做的是编写一个按钮,该按钮将在单击时拉动主行并将所有其他行与其进行比较。从第一行开始,每次该列与主条目匹配时,都会将 1 点分配给声明的整数。当该行被完全读取后,整数将存储在“总点数”列中。然后它继续到下一行答案。

我希望我的措辞方式有意义,如果有更简单的方法,我愿意接受建议。我真的不需要任何帮助来建立与 sql 数据库的连接。任何帮助将不胜感激,提前感谢任何人的时间。如果有帮助,我可以提供更多详细信息。

Let's say, for example, this is a quiz where the answers are already loaded into a database from different students. Inside of the table with various student entries containing various student's answers there is a row "masterentry" with all of the correct answers.

What I would like to do is code a button that will pull the master row on click and compare every other row against it. Starting with the first row, every time the column matches the master entry 1 point is assigned to a declared integer. When the row has completely been read the integer is stored in a "totalpoints" column. Then it moves on to the next row of answers.

I hope this makes sense the way I worded it, if there is an easier way to go about it I am open to suggestions. I don't really need any help establishing the connection to the sql database. Any help would be greatly appreciated, thanks in advance for anyone's time. I can provide more details if it would be helpful.

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

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

发布评论

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

评论(1

維他命╮ 2025-01-15 20:37:30

只是基于模糊的模式想法的粗略猜测。您只需从 .NET 调用此查询(最好存储在存储过程中,传入 @QuizID),除非您确实希望在将所有数据拉取到客户端后通过循环来降低效率。 ..

;WITH master AS (SELECT a1 = Answer1, a2 = Answer2, ...
  FROM dbo.Quiz
  WHERE QuizID = @QuizID
  AND Answer = 'masterentry'
)
SELECT a.StudentID,
    Score = CASE WHEN a.Answer1 = master.a1 THEN 1 ELSE 0 END
          + CASE WHEN a.Answer2 = master.a2 THEN 1 ELSE 0 END
          + ...
FROM dbo.Quiz AS a
CROSS JOIN master
WHERE a.QuizID = @QuizID
AND a.Answer <> 'masterentry' -- or a.StudentID IS NOT NULL?

根据数据类型,这里可能有一些快捷方式。例如,如果测验是对/错,您可以采取一些小技巧来减少 ... 部分。

Just a rough guess based on vague idea of schema. You would just call this query from .NET (preferably stored in stored procedure, passing in a @QuizID) unless you really want to do it less efficiently by looping after pulling all of the data to the client...

;WITH master AS (SELECT a1 = Answer1, a2 = Answer2, ...
  FROM dbo.Quiz
  WHERE QuizID = @QuizID
  AND Answer = 'masterentry'
)
SELECT a.StudentID,
    Score = CASE WHEN a.Answer1 = master.a1 THEN 1 ELSE 0 END
          + CASE WHEN a.Answer2 = master.a2 THEN 1 ELSE 0 END
          + ...
FROM dbo.Quiz AS a
CROSS JOIN master
WHERE a.QuizID = @QuizID
AND a.Answer <> 'masterentry' -- or a.StudentID IS NOT NULL?

There may be some shortcuts here based on the data types. E.g. if the quiz is true/false there are some little tricks you can do to reduce the ... part.

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