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

Finish No.1

parent aeca3c8e
......@@ -129,8 +129,29 @@ CALL Deliver_Status();
### 5. 输出2017-4-1至2017-5-1期间(不包括2017-4-1和2017-5-1这两天),收货地址包含“景德镇”的配送信息,输出格式化为“快递员姓名/物流号”,多个物流号之间以逗号隔开
```mysql
-- 这样是错误的:SELECT C.Cname AS "快递员姓名", P.Pno AS "物流号" FROM C, P JOIN D ON D.Pno = P.Pno WHERE P.Pto = '景德镇' AND D.Dtime BETWEEN '2017-4-1' AND '2017-5-1' GROUP BY C.Cname, P.Pno;
-- Between 是包含左右两边端点的,所以不要用
-- FROM .. JOIN .. ON 是一种关联关系,通过 ON 的条件关联两张表
SELECT CONCAT(C.Cname, '/', D.Pno) AS '快递员姓名/物流号'
FROM
P
JOIN D ON D.Pno = P.Pno
JOIN C ON C.Cno = D.Cno
WHERE
'2017-4-1' < D.Dtime AND D.Dtime < '2017-5-1';
```
### 6. 用SQL写一个完整性规则,当插入配送信息时,将包裹状态置为“派件中”
> 即为加入一个触发器,如果在 D 表插入数据,那么根据 Pno,将 P 表中相同 Pno 的 Pstatus 改为「派件中」。
```mysql
DELIMITER //
CREATE TRIGGER Automatic_Change AFTER INSERT ON D FOR EACH ROW
BEGIN
UPDATE P SET Pstatus = '派件中' WHERE Pno = New.Pno;
END //
DELIMITER ;
```
\ No newline at end of file
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