diff --git "a/11 \351\202\271\344\272\250\344\274\237/20231010\344\275\234\344\270\232.md" "b/11 \351\202\271\344\272\250\344\274\237/20231010\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..b39a67bab176fe2486fff8019c82cbff2c589d3d --- /dev/null +++ "b/11 \351\202\271\344\272\250\344\274\237/20231010\344\275\234\344\270\232.md" @@ -0,0 +1,125 @@ +## 笔记 + +1) 分支结构之 IF + +IF 表达式1 THEN 操作1 sql语句 +[ELSEIF 表达式2 THEN 操作2]…… +[ELSE 操作N] +END IF + +特点:① 不同的表达式对应不同的操作 ② 使用在begin end中 + + + + + +2. 分支结构之 CASE + + 情况1 + +CASE 表达式 +WHEN 值1 THEN 结果1或语句1(如果是语句,需要加分号) +WHEN 值2 THEN 结果2或语句2(如果是语句,需要加分号) +... +ELSE 结果n或语句n(如果是语句,需要加分号) +END [case](如果是放在begin end中需要加上case,如果放在select后面不需要) + + + + 情况2 + +CASE +WHEN 条件1 THEN 结果1或语句1(如果是语句,需要加分号) +WHEN 条件2 THEN 结果2或语句2(如果是语句,需要加分号) +... +ELSE 结果n或语句n(如果是语句,需要加分号) +END [case](如果是放在begin end中需要加上case,如果放在select后面不需要) + + + + + +3) 循环结构之LOOP + +[loop_label:] LOOP +循环执行的语句 +END LOOP [loop_label] + + + + + +4) 循环结构之WHILE + + + +[while_label:] WHILE 循环条件 DO +循环体 +END WHILE [while_label]; + +# 作业 + + + +~~~mysql +#1. 创建函数test_if_case(),实现传入成绩,如果成绩>90,返回A,如果成绩>80,返回B,如果成绩>60,返回C,否则返回D +#要求:分别使用if结构和case结构实现 + +#方式1:if +drop procedure test_if_case; +delimiter // +create procedure test_if_case(in num double(4,1)) +begin + if num <0 or num >100 then select '傻逼'; + elseif num > 90 then select 'A'; + elseif num > 80 then select 'B'; + elseif num > 60 then select 'C'; + else select 'D'; + end if; +end // +delimiter ; +call test_if_case(66); +#方式2:case when ... +drop procedure test_if_case; +delimiter // +create procedure test_if_case(in num double(4,1)) +begin + case + when num <0 or num >100 then select '傻逼'; + when num > 90 then select 'A'; + when num > 80 then select 'B'; + when num > 60 then select 'C'; + else select 'D'; + end case; +end // +delimiter ; +call test_if_case(55); + + +#2. 创建存储过程test_if_pro(),传入工资值,如果工资值<3000,则删除工资为此值的员工, +# 如果3000 <= 工资值 <= 5000,则修改此工资值的员工薪资涨1000,否则涨工资500 +drop procedure test_if_pro; +delimiter // +create procedure test_if_pro(in num double(10,2)) +begin + select * from employees where salary=num; + if num <0 then select '输入错误'; + elseif num <3000 then delete from employees where salary=num; + elseif 3000 <= num and num <= 5000 then update employees set salary=salary+1000 where salary=num; + else update employees set salary=salary+500 where salary=num; + end if; + if num <3000 then SELECT * from employees where salary=num; + elseif 3000 <= num and num <= 5000 then SELECT * from employees where salary=num+1000; + else SELECT * from employees where salary=num+500; + end if; +end // +delimiter ; +set @a = 2900; +call test_if_pro(@a); +~~~ + + + +``` + +``` diff --git "a/11 \351\202\271\344\272\250\344\274\237/10.7.md" "b/11 \351\202\271\344\272\250\344\274\237/2023107.md" similarity index 100% rename from "11 \351\202\271\344\272\250\344\274\237/10.7.md" rename to "11 \351\202\271\344\272\250\344\274\237/2023107.md" diff --git "a/11 \351\202\271\344\272\250\344\274\237/202310.8.md" "b/11 \351\202\271\344\272\250\344\274\237/2023108.md" similarity index 100% rename from "11 \351\202\271\344\272\250\344\274\237/202310.8.md" rename to "11 \351\202\271\344\272\250\344\274\237/2023108.md" diff --git "a/11 \351\202\271\344\272\250\344\274\237/2023109.md" "b/11 \351\202\271\344\272\250\344\274\237/2023109.md" new file mode 100644 index 0000000000000000000000000000000000000000..b39a67bab176fe2486fff8019c82cbff2c589d3d --- /dev/null +++ "b/11 \351\202\271\344\272\250\344\274\237/2023109.md" @@ -0,0 +1,125 @@ +## 笔记 + +1) 分支结构之 IF + +IF 表达式1 THEN 操作1 sql语句 +[ELSEIF 表达式2 THEN 操作2]…… +[ELSE 操作N] +END IF + +特点:① 不同的表达式对应不同的操作 ② 使用在begin end中 + + + + + +2. 分支结构之 CASE + + 情况1 + +CASE 表达式 +WHEN 值1 THEN 结果1或语句1(如果是语句,需要加分号) +WHEN 值2 THEN 结果2或语句2(如果是语句,需要加分号) +... +ELSE 结果n或语句n(如果是语句,需要加分号) +END [case](如果是放在begin end中需要加上case,如果放在select后面不需要) + + + + 情况2 + +CASE +WHEN 条件1 THEN 结果1或语句1(如果是语句,需要加分号) +WHEN 条件2 THEN 结果2或语句2(如果是语句,需要加分号) +... +ELSE 结果n或语句n(如果是语句,需要加分号) +END [case](如果是放在begin end中需要加上case,如果放在select后面不需要) + + + + + +3) 循环结构之LOOP + +[loop_label:] LOOP +循环执行的语句 +END LOOP [loop_label] + + + + + +4) 循环结构之WHILE + + + +[while_label:] WHILE 循环条件 DO +循环体 +END WHILE [while_label]; + +# 作业 + + + +~~~mysql +#1. 创建函数test_if_case(),实现传入成绩,如果成绩>90,返回A,如果成绩>80,返回B,如果成绩>60,返回C,否则返回D +#要求:分别使用if结构和case结构实现 + +#方式1:if +drop procedure test_if_case; +delimiter // +create procedure test_if_case(in num double(4,1)) +begin + if num <0 or num >100 then select '傻逼'; + elseif num > 90 then select 'A'; + elseif num > 80 then select 'B'; + elseif num > 60 then select 'C'; + else select 'D'; + end if; +end // +delimiter ; +call test_if_case(66); +#方式2:case when ... +drop procedure test_if_case; +delimiter // +create procedure test_if_case(in num double(4,1)) +begin + case + when num <0 or num >100 then select '傻逼'; + when num > 90 then select 'A'; + when num > 80 then select 'B'; + when num > 60 then select 'C'; + else select 'D'; + end case; +end // +delimiter ; +call test_if_case(55); + + +#2. 创建存储过程test_if_pro(),传入工资值,如果工资值<3000,则删除工资为此值的员工, +# 如果3000 <= 工资值 <= 5000,则修改此工资值的员工薪资涨1000,否则涨工资500 +drop procedure test_if_pro; +delimiter // +create procedure test_if_pro(in num double(10,2)) +begin + select * from employees where salary=num; + if num <0 then select '输入错误'; + elseif num <3000 then delete from employees where salary=num; + elseif 3000 <= num and num <= 5000 then update employees set salary=salary+1000 where salary=num; + else update employees set salary=salary+500 where salary=num; + end if; + if num <3000 then SELECT * from employees where salary=num; + elseif 3000 <= num and num <= 5000 then SELECT * from employees where salary=num+1000; + else SELECT * from employees where salary=num+500; + end if; +end // +delimiter ; +set @a = 2900; +call test_if_pro(@a); +~~~ + + + +``` + +``` diff --git "a/11 \351\202\271\344\272\250\344\274\237/20239.24.md" "b/11 \351\202\271\344\272\250\344\274\237/2023924.md" similarity index 100% rename from "11 \351\202\271\344\272\250\344\274\237/20239.24.md" rename to "11 \351\202\271\344\272\250\344\274\237/2023924.md" diff --git "a/11 \351\202\271\344\272\250\344\274\237/9.28.md" "b/11 \351\202\271\344\272\250\344\274\237/2023928.md" similarity index 100% rename from "11 \351\202\271\344\272\250\344\274\237/9.28.md" rename to "11 \351\202\271\344\272\250\344\274\237/2023928.md"