Auto commit
This commit is contained in:
parent
3a32020d4e
commit
783148afe6
@ -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 ;
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user