回答編集履歴
2
体裁
test
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
```SQL
|
8
8
|
|
9
|
+
update 仕入 set
|
10
|
+
|
9
|
-
|
11
|
+
原価=(select 原価 from 売上 where 商品id=仕入.商品ID group by 原価)
|
10
12
|
|
11
13
|
where exists(select 1 from 売上 where 商品id=仕入.商品ID)
|
12
14
|
|
1
タグを付けた
test
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
|
5
5
|
同じだと仮定して(商品IDで一意になる状態で更新しないとまずいので)
|
6
6
|
|
7
|
-
|
7
|
+
```SQL
|
8
8
|
|
9
9
|
update 仕入 set 原価=(select 原価 from 売上 where 商品id=仕入.商品ID group by 原価)
|
10
10
|
|
11
11
|
where exists(select 1 from 売上 where 商品id=仕入.商品ID)
|
12
12
|
|
13
|
-
|
13
|
+
```
|
14
14
|
|
15
15
|
※where 条件は売上の無い商品IDについて更新されないようにするためです
|