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

Half way No.1

parent e5086838
......@@ -65,17 +65,36 @@ SELECT P.Pno AS "包裹物流号", C.Cname AS "快递员姓名", D.Dtime AS "配
>
```mysql
SELECT C.Cname, C.Cage, C.Csalary FROM C, D WHERE D.Dtime >= '2017-04-01' AND D.Dtime <= '2017-05-01' HAVING COUNT(D.Cno)>1;
SELECT C.Cname, C.Cage, C.Csalary
FROM C JOIN D ON C.Cno = D.Cno
WHERE
D.Dtime BETWEEN '2017-04-01' AND '2017-05-01'
GROUP BY C.Cname, C.Cage, C.Csalary
HAVING
COUNT(D.Cno) > 100;
```
### 3. 对所有年龄低于40的快递员,若底薪小于2500,则增加400工资,若大于等于2500,则增加200工资
> 不能用游标,因为游标是只读的。
```mysql
SELECT WHERE Cage < 40;
-- 两条语句
UPDATE C SET Csalary = Csalary + 400 WHERE Csalary < 2500 AND Cage IN (SELECT Cage FROM C WHERE Cage < 40);
UPDATE C SET Csalary = Csalary + 200 WHERE Csalary >= 2500 AND Cage IN (SELECT Cage FROM C WHERE Cage < 40);
-- 一个 IF
UPDATE C
SET Csalary = IF(Csalary < 2500, Csalary + 400, IF(Csalary >= 2500, Csalary + 200, Csalary))
WHERE Cage IN (SELECT Cage FROM C WHERE Cage < 40);
```
### 4. 给定仓库的名称,输出为在该仓库有存储记录,且包裹状态为“派件中”的配送信息,输出格式为“快递员姓名/收货地址/收件人姓名/收件人联系方式/配送状态”,这里的“配送状态”设置方法为:若配送时间(Dtime)距今超过5天,则设置为“异常”;否则设置为“正常”
```mysql
```
### 5. 输出2017-4-1至2017-5-1期间(不包括2017-4-1和2017-5-1这两天),收货地址包含“景德镇”的配送信息,输出格式化为“快递员姓名/物流号”,多个物流号之间以逗号隔开
### 6. 用SQL写一个完整性规则,当插入配送信息时,将包裹状态置为“派件中”
......
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