Auto commit

This commit is contained in:
smallkun 2025-03-06 23:55:54 +08:00
parent 3dae5b6d37
commit eaaf651831
2 changed files with 45 additions and 1 deletions

View File

@ -335,10 +335,54 @@ 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 ;
#10
DELIMITER $$
DROP PROCEDURE IF EXISTS pro_GetTopStudent;
CREATE PROCEDURE pro_GetTopStudent(IN in_cid CHAR(11), OUT out_stuname VARCHAR(50))
BEGIN
SELECT st.stuname INTO out_stuname
FROM tb_students st, tb_scores sc
WHERE st.stuid = sc.student_id AND sc.course_id = in_cid
ORDER BY sc.score DESC
LIMIT 1;
END $$
DELIMITER ;
CALL pro_GetTopStudent(1, @result);
SELECT @result;
```