//判断姓名为"小和"的学员成绩是否通过考试,按一下格式输出: 60以下E等级 60-70 D等级 70-80 C等级 80-90 B等级 90-100 A等级
drop procedure if exists kt;
create procedure kt()
--定义变量保存成绩
begin
declare cjj int;
--赋值
select cii=(
select cj from score where stuId=(
select stuId from stuinfo
where name='小和'
)
);
--case when then 语句判断
case when cj>=90 and cj <100
then select 'A等级';
when cj >=80 and cj<90
then select 'B等级';
when cj >=70 and cj<80
then select 'C等级';
when cj >=60 and cj<70
then select
'D等级';
when cj<60
then select 'C等级';
end case;
end;
--调用存储过程
call kt();
--2.case....when的用法 1人一下的说没有,1-3人说偏少,3-4人说中等,4人以上说偏多
select address,count(cj) 人数 ,case when count(cj)<1 then '没人'
when count(cj)<3 and count(cj)>=1 then '偏少'
when count(cj)<4 and count(cj)>=3 then '中等'\
when count(cj)>=4 then '偏多'
end '考试人数' from stuInfo st left join score s on st.stuId=s.stuId group by address;
--使用存储过程打印1-50
drop procedure if exists st;
create procedure st()
begin
--定义变量 保存初始值
declare i int default 1;
--定义变量 拼接 结果 初始值为''
declare str varchar(200) default '' ;
--开始循环
while(i<=50)
do
set str=concat(str,i,',');
--更新变量
set i=i+1;
end while;
--输出
select str;
end;
--调用
call st();
--3.输出1-100中5的倍数
create procedure st2()
begin
--定义变量,保存初始值
declare 1 int default 1;
--定义变量 保存拼接结果
declare str varchar(200) default '';
--开始循环
while(i<=100)
do
if(i%5==0)
then
set str=concat(str,i,'');
end if;
--更新变量
set i=i+1;
end while;
--输出结果
select str 结果;
end;
call st2();