MySQL存储过程练习

没有数据库的先执行50q数据库

实验1:创建一个存储过程ppt1,根据班级编号,统计该班人数,还统计该班每门课程平均分,并执行存储过程
CREATE DEFINER=’root’@’localhost PROCEDURE’ppt1’(in cla varchar(5),out cut int)
BEGIN
Select count(*) into cut from student where class=cla;
Select cno,avg(degree) from student inner join score on syudent.sno=score.sno where class=cla group by cno;
END
call pp1('95033',@cou);
select @cou;

实验2.创建一个存储过程ppt2,根据给定的学生姓名返回该学生的学号和成绩。 
CREATE PROCEDURE `ppt2` (in sname VARCHAR(4))
BEGIN
Select sno,degree from score,student where score.sno=student.sno and student.sno=sname;
END
Call pp2 (‘李军’);

实验3.创建一个存储过程ppt3,根据给定的学号和课程号,将他这门课不及格成绩改为60分,并显示出学号,课程号,成绩。 
CREATE DEFINER=’root’@’localhost PROCEDURE’ppt3’(in sn varchar(3),in cn varchar(5))
BEGIN
Update score set degree=60 where sno=sn and cno=cn and degree<60;
select * from score where sno=sn and cno=cn;
END
call pp3('105','3-245');
update score set degree=55 where sno='103'and cno='3-245';

实验4:创建一个存储过程ppt4,检索成绩低于课程‘3-105’平均分的学生的学号,姓名,课程名,成绩
CREATE DEFINER=’root’@’localhost PROCEDURE’ppt4’()
BEGIN
Declare av decimal(10,1);
Select avg(degree) into av from score where cno=’ 3-105’;
END

实验5.请撰写一个存储过程ppt5:能根据用户输入的课程号,输出该课程平均分,最高分,最低分到三个参数变量中,以供其它程序使用
CREATE DEFINER=`root`@`localhost` PROCEDURE `ppt5`(in cn varchar(5),out av int,out ma int)
BEGIN
select round(avg(degree)),round(max(degree)) into av,ma from score where cno=cn;
END

你可能感兴趣的:(MySQL数据库应用技术)