ZBLOG

编写存储过程p_studentinfobyclass实现查询给定班级的学生学号姓名、课程号和成绩 /* Navicat Premium Data Transfer Source Server : loddb Source Server Type : MySQL Source Server Version : 50553 Source Host : localhost:3306 Source Schema : wang...

DELIMITER // CREATE PROCEDURE p_studentinfobyclass (IN classname VARCHAR(10)) BEGIN

SELECT students.Sno, students.Sname, stc.Cno, stc.Score
FROM students 
INNER JOIN stc ON students.Sno = stc.Sno 
WHERE stc.Cno IN (
    SELECT courses.Con FROM courses WHERE courses.cname = classname
);

END// DELIMITER ;

Explanation:

  • The procedure name is “p_studentinfobyclass”, and it takes one input parameter “classname” of type VARCHAR(10).
  • The procedure selects student information from the “students” table and course information from the “stc” table.
  • It uses an inner join to match records in both tables based on the student ID (Sno) column.
  • The where clause filters the results by selecting only those records whose course number (Cno) is included in a subquery that selects all course numbers for a given class name.
  • The result set includes columns for student ID (Sno), student name (Sname), course number (Cno), and score.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=3600

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?