From 1101eebe94152ace643b15e01694c884cf6d2be9 Mon Sep 17 00:00:00 2001 From: smallkun Date: Fri, 28 Mar 2025 10:38:36 +0800 Subject: [PATCH] Auto commit --- 3月调考/MySQL.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/3月调考/MySQL.md b/3月调考/MySQL.md index 57deb92..cf2fd66 100644 --- a/3月调考/MySQL.md +++ b/3月调考/MySQL.md @@ -580,5 +580,25 @@ CREATE VIEW v_education AS SELECT s.`name` '学生姓名', c.`name` '课程名称', l.`schedule` '学习进度', l.createtime '创建时间' FROM t_student s, t_learn l, t_course c WHERE s.id = l.s_id AND l.c_id = c.id; + +#8 +CREATE TRIGGER tri_insert_student_learn +AFTER INSERT ON t_student +FOR EACH ROW +BEGIN + INSERT INTO t_learn (s_id, c_id, schedule, createtime) + VALUES (NEW.id, 10001, 0, '2025-01-01'); +END + +#9 +CREATE PROCEDURE `sp_get_student_courses`( + IN in_student_id INT, + OUT out_course_count INT +) +BEGIN + SELECT COUNT(DISTINCT c_id) INTO out_course_count + FROM t_learn + WHERE s_id = in_student_id ; +END ```