[英]Sql: using table's column value as a parameter for the stored procedure
So I want to create a table with two columns. 所以我想创建一个包含两列的表。 The first column has studentIDs and the other column has GPA for that corresponding student.
第一列具有学生ID,另一列具有该对应学生的GPA。 I have a stored procedure called sp_calculateGPA that looks up student's grades based on their student ID and calculates their GPA.
我有一个名为sp_calculateGPA的存储过程,该存储过程根据学生的学生ID查找学生的成绩并计算其GPA。
Can I use the first column value as a parameter for the stored procedure to get the GPA value for the second column? 我可以使用第一列的值作为存储过程的参数来获取第二列的GPA值吗? If yes, how can I do that?
如果是,我该怎么做?
Thank you 谢谢
You can make a stored procedure that takes in @StudentID INT
and then does: 您可以创建一个存储过程,该存储过程接受
@StudentID INT
,然后执行以下操作:
SELECT GPA FROM tableName WHERE studentID = @StudentID
If you need to do summing and averaging of the grades you can group by the studentID and use aggregate functions such as SUM
and COUNT
如果需要对成绩进行求和和平均,可以按studentID进行分组,并使用汇总功能,例如
SUM
和COUNT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.