更新 '2207/习题答案/2-18.md'

This commit is contained in:
smallkun 2025-02-18 09:49:43 +08:00
parent 167c79c70f
commit 48da8b8d59

View File

@ -62,4 +62,65 @@ void main()
printf("%d\n",i);
}
```
## MySQL
```sql
#1
ALTER TABLE t_hotel ADD `level` CHAR(10) DEFAULT '暂无评级';
#2
INSERT INTO t_hotel()
VALUES(DEFAULT, '苹果酒店', '无名街356号', '138-1258-0000', '五星');
#3
UPDATE t_room r
SET r.price = r.price+100
WHERE r.hid = (
SELECT hid
FROM t_hotel
WHERE hname = '香蕉酒店'
);
#4
SELECT c.cname, c.integral,
IF(c.integral<1000, '普通会员',
IF(c.integral<3000, '中级会员',
IF(c.integral<5000, '高级会员', '顶级会员')))
FROM t_client c;
#5
SELECT h.hid, ROUND(AVG(r.price), 2) p
FROM t_hotel h, t_room r
WHERE h.hid = r.hid
GROUP BY h.hid
ORDER BY p DESC;
#6
SELECT c.cid, c.cname, SUM(r.price) s
FROM t_client c, t_booking b, t_room r
WHERE c.cid = b.cid AND r.rid = b.rid
GROUP BY c.cid
ORDER BY s DESC
LIMIT 1;
#7
CREATE VIEW v_hotel AS
SELECT DATE_FORMAT(b.btime,'%Y-%m') d, SUM(r.price)
FROM t_booking b, t_room r
WHERE b.rid = r.rid
GROUP BY d;
#8
DELIMITER $$
CREATE TRIGGER tri_updateLevel
BEFORE UPDATE ON t_client
FOR EACH ROW
BEGIN
IF NEW.integral <2500 THEN
SET NEW.`level` = '初级会员';
ELSEIF NEW.integral <5000 THEN
SET NEW.`level` = '中级会员';
ELSE
SET NEW.`level` = '高级会员';
END IF;
END $$
DELIMITER ;
#9
```