Auto commit
This commit is contained in:
parent
77130d67f9
commit
1a337cdb21
@ -248,7 +248,7 @@ CREATE VIEW v_book AS
|
||||
SELECT b.genre, a.author_name, COUNT(*) c
|
||||
FROM tb_books b, tb_authors a
|
||||
WHERE b.note = a.author_name
|
||||
GROUP BY b.genre, a.author_id
|
||||
GROUP BY b.genre, a.author_id #按照图书类别和作者名称进行分组
|
||||
HAVING COUNT(*) = ( #子查询用来统计这个类别中 数量最多的作者的图书数量
|
||||
SELECT COUNT(*)
|
||||
FROM tb_books
|
||||
@ -258,6 +258,34 @@ HAVING COUNT(*) = ( #子查询用来统计这个类别中 数量最多的作者
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
#10
|
||||
DELIMITER $$
|
||||
DROP TRIGGER IF EXISTS tri_updateCentury;
|
||||
CREATE TRIGGER tri_updateCentury
|
||||
BEFORE UPDATE ON tb_books
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
#方式一
|
||||
/*
|
||||
计算出世纪数+字符串拼接
|
||||
IF NEW.publication_date <> OLD.publication_date THEN
|
||||
SET NEW.century = CONCAT(FLOOR(YEAR(NEW.publication_date)/100) + 1, '世纪');
|
||||
END IF;
|
||||
*/
|
||||
#方式二 使用多分支IF
|
||||
IF NEW.publication_date <> OLD.publication_date THEN
|
||||
IF YEAR(NEW.publication_date) BETWEEN 1800 AND 1899 THEN
|
||||
SET NEW.century = '19世纪';
|
||||
ELSEIF YEAR(NEW.publication_date) BETWEEN 1900 AND 1999 THEN
|
||||
SET NEW.century = '20世纪';
|
||||
ELSEIF YEAR(NEW.publication_date) BETWEEN 2000 AND 2099 THEN
|
||||
SET NEW.century = '21世纪';
|
||||
END IF;
|
||||
END IF;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
SELECT CONCAT(FLOOR(YEAR(publication_date)/100) + 1, '世纪')
|
||||
FROM tb_books;
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user