From 783148afe6d66f87d96ffad0bb721d8460fbc1ea Mon Sep 17 00:00:00 2001
From: smallkun <smallerkun@foxmail.com>
Date: Wed, 5 Mar 2025 08:54:50 +0800
Subject: [PATCH] Auto commit

---
 2208/天天乐学考试答案/MySQL练习(一).md | 61 ++++++------------------
 1 file changed, 14 insertions(+), 47 deletions(-)

diff --git a/2208/天天乐学考试答案/MySQL练习(一).md b/2208/天天乐学考试答案/MySQL练习(一).md
index 8643e56..0e8b884 100644
--- a/2208/天天乐学考试答案/MySQL练习(一).md
+++ b/2208/天天乐学考试答案/MySQL练习(一).md
@@ -305,53 +305,20 @@ DELIMITER ;
 ### 第四套
 
 ```sql
-#1
-ALTER TABLE tb_students MODIFY gender ENUM('男', '女', '未知');
-#2
-ALTER TABLE tb_scores MODIFY score FLOAT(7, 2);
-#3
-CREATE TABLE tb_scores_bak1 AS
-SELECT *
-FROM tb_scores;
-#4
-UPDATE test1 t1, (
-	SELECT tname, CONCAT(tname,'@',COUNT(*)) str
-	FROM test1
-	GROUP BY tname
-	HAVING COUNT(*) IN (3, 4)
-)t2
-SET t1.tname = t2.str
-WHERE t1.tname = t2.tname;
-
-#5
-SELECT *
-FROM tb_courses c
-ORDER BY c.cid+0
-LIMIT 4, 11;
-
-#6
-SELECT s.stuname, TIMESTAMPDIFF(YEAR,s.birthday,'2023-12-01')
-FROM tb_students s
-WHERE TIMESTAMPDIFF(YEAR,s.birthday,'2023-12-01') BETWEEN 30 AND 40;
-
-#7
-SELECT st.stuname, st.gender, st.birthday, c.cname, sc.score,
-	IF(sc.score >= 90, '优秀', 
-	IF(sc.score >= 80, '良好', 
-	IF(sc.score >= 70, '中等', 
-	IF(sc.score >= 60, '及格', '不及格'))))
-FROM tb_students st, tb_scores sc, tb_courses c
-WHERE st.stuid = sc.student_id AND sc.course_id = c.cid
-ORDER BY sc.score DESC;
-
-#8
-CREATE VIEW v_scores AS
-SELECT c.cname, CEIL(AVG(sc.score)), MAX(sc.score), MIN(sc.score)
-FROM tb_students st, tb_scores sc, tb_courses c
-WHERE st.stuid = sc.student_id AND sc.course_id = c.cid
-GROUP BY c.cid;
-
-#9
+DELIMITER $$
+CREATE TRIGGER tri_updateAgeGroup
+BEFORE UPDATE ON tb_students
+FOR EACH ROW
+BEGIN
+	IF YEAR(NEW.birthday) BETWEEN 2004 AND 2024 THEN
+		SET NEW.age_group = '青年';
+	ELSEIF YEAR(NEW.birthday) BETWEEN 1984 AND 2003 THEN
+		SET NEW.age_group = '中年';
+	ELSEIF YEAR(NEW.birthday) < 1984 THEN
+		SET NEW.age_group = '老年';
+	END IF;
+END $$
+DELIMITER ;
 ```