简体   繁体   English

SQL:使用表的列值作为存储过程的参数

[英]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进行分组,并使用汇总功能,例如SUMCOUNT

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

相关问题 使用 SQL 存储过程返回表的行 - Using SQL stored procedure to return row of table MySQL:当存储过程参数名与表列名相同时 - MySQL : When stored procedure parameter name is the same as table column name SQL 雪花上的存储过程将绑定列视为字符串,并且它没有从表中获取其值 - SQL Stored procedure on snowflake is treating binded column as string and its not getting its value from the table 存储过程使用动态 SQL 语句存储在数据库列中 - Stored procedure using dynamic SQL statement stored in database column MySQL 存储过程将参数输入与表值进行比较 - MySQL Stored Procedure comparing parameter input with a table value SQL-检查列是否存在于存储过程中(表是变量) - SQL - check if column exists within stored procedure (table is variable) 在存储过程中使用参数获取动态表名称 - Using parameter in stored procedure to get dynamic table name 将列数的20%与存储过程中的已知值进行比较 - compare 20% of a column's number with a known value in stored procedure 根据其值设置SQL存储过程的输入变量 - Set input var of SQL stored procedure depending on it's value MySQL 5.7,使用存储过程中的变量按列名对表进行排序 - MySQL 5.7, sort table by column name using a variable in Stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM