针对SPJ数据库完成带子查询的更新操作: ① 新建一个数据表tb_sumqty,用来存放每个工程使用的零件总数,并把结果存入数据表。 ② 将天津供应商供给天津工程的零件数增加10%。 ③ 删除天津供应商供应齿轮零件的记录。
时间: 2024-02-05 17:13:14 浏览: 50
spj查询零件、工程、供应商查询
针对SPJ数据库完成带子查询的更新操作如下:
① 新建一个数据表tb_sumqty,用来存放每个工程使用的零件总数,并把结果存入数据表。
```sql
CREATE TABLE tb_sumqty (
jno CHAR(4),
sumqty INT
);
INSERT INTO tb_sumqty (jno, sumqty)
SELECT jno, SUM(qty) AS sumqty
FROM spj
GROUP BY jno;
```
② 将天津供应商供给天津工程的零件数增加10%。
```sql
UPDATE spj
SET qty = qty * 1.1
WHERE jno = 'TJ' AND sno IN (
SELECT sno
FROM suppliers
WHERE city = 'TJ'
) AND jno IN (
SELECT jno
FROM projects
WHERE city = 'TJ'
);
```
③ 删除天津供应商供应齿轮零件的记录。
```sql
DELETE FROM spj
WHERE jno IN (
SELECT jno
FROM projects
WHERE city = 'TJ'
) AND sno IN (
SELECT sno
FROM suppliers
WHERE city = 'TJ'
) AND jno IN (
SELECT jno
FROM spj
WHERE jno = 'TJ' AND jno IN (
SELECT jno
FROM projects
WHERE city = 'TJ'
) AND sno IN (
SELECT sno
FROM suppliers
WHERE city = 'TJ' AND sname = '齿轮供应商'
)
);
```
阅读全文