Verified Commit c0cfb3af authored by Kiryuu Sakuya's avatar Kiryuu Sakuya 🎵
Browse files

Finally

parent cdfc35ad
......@@ -266,7 +266,39 @@ FROM
### 7. 编写一个存储过程,输入为一日期字符串(格式为 `yyyy-MM-dd`)和制作电影的公司名称,如果该公司的电影上映时间晚于输入中日期字符串的时间且其票价小于 100 ,则增加其原票价的 20%,如果其票价大于等于 100,则增加其原票价的 10%。同时按该公司的电影的上映时间从早到晚的顺序分别打印一行字符串「电影名称 & 票价」
```mysql
DELIMITER //
CREATE PROCEDURE Add_Price(IN input_date DATE, IN input_corpname VARCHAR(30))
BEGIN
DECLARE RESULT VARCHAR(60) DEFAULT '';
DECLARE Year YEAR;
DECLARE MovieName VARCHAR(50);
DECLARE DetailTime DATE;
DECLARE CorpName VARCHAR(30);
DECLARE Price DOUBLE;
DECLARE COUNT INT DEFAULT 0;
DECLARE I INT DEFAULT 0;
DECLARE Cursor_Check CURSOR FOR SELECT M.Mname, M.Myear, I.Iprice, I.Itime FROM I LEFT JOIN M ON M.Mno = I.Mno LEFT JOIN C ON C.Cno = M.Cno WHERE C.Cname = input_corpname ORDER BY Itime ASC;
SELECT COUNT(*) INTO COUNT FROM I;
OPEN Cursor_Check;
REPEAT
SET I := I + 1;
FETCH Cursor_Check INTO MovieName, Year, Price, DetailTime;
IF input_date != DetailTime AND input_date < DetailTime AND Price < 100 THEN
SET @_Price = Price * 1.2;
UPDATE I SET I.Iprice = @_Price WHERE I.Itime = DetailTime;
ELSEIF input_date != DetailTime AND input_date < DetailTime AND Price >= 100 THEN
SET @_Price = Price * 1.1;
UPDATE I SET I.Iprice = @_Price WHERE I.Itime = DetailTime;
END IF;
SELECT CONCAT(M.Mname, '/', I.Iprice) AS '电影名称/票价'
FROM I
LEFT JOIN M ON M.Mno = I.Mno
LEFT JOIN C ON C.Cno = M.Cno
WHERE C.Cname = input_corpname ORDER BY Itime ASC;
UNTIL I >= COUNT END REPEAT;
CLOSE Cursor_Check;
END //
DELIMITER ;
```
### 8. 用 SQL 编写一个完整性规则,当插入上映信息时,如果公司名称为 `Warner Bros` 并且该公司的电影的制作年份大于 2012,则自动将票价提高 20%
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment