mysql创建存储过程P5,查询每个学生的修课门数,要求列出学生学号、姓名及修课门数,包括没修课的学生
时间: 2024-03-06 16:46:44 浏览: 97
可以尝试使用以下 SQL 语句创建存储过程 P5:
```
CREATE PROCEDURE P5()
BEGIN
SELECT S.sid, S.sname, COUNT(C.sid) AS num_of_courses
FROM student S
LEFT JOIN sc C ON S.sid = C.sid
GROUP BY S.sid, S.sname;
END;
```
这个存储过程可以列出每个学生的学号、姓名以及修课门数,包括没修课的学生。使用 LEFT JOIN 可以让没有成绩记录的学生也出现在结果中,COUNT 函数计算每个学生修课的门数。在存储过程中使用 GROUP BY 子句可以按照学号和姓名分组,确保每个学生只出现一次。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/octet-stream](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)