回答編集履歴

6

変更

2017/09/07 07:29

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
File without changes

5

変更

2017/09/07 07:29

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -38,11 +38,11 @@
38
38
 
39
39
 
40
40
 
41
- update テーブルA set P=t1.P
41
+ update テーブルA set P=テーブルB.P
42
42
 
43
- from (select * from テーブルB) t1
43
+ from テーブルB
44
44
 
45
- where テーブルA.id=t1.id;
45
+ where テーブルA.id=テーブルB.id;
46
46
 
47
47
 
48
48
 

4

変更

2017/09/07 07:29

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -46,6 +46,18 @@
46
46
 
47
47
 
48
48
 
49
+ または
50
+
51
+
52
+
53
+ update テーブルA set P=t1.P
54
+
55
+ from (select テーブルB.id, テーブルB.P from テーブルB join テーブルA using(id)) t1
56
+
57
+ where テーブルA.id=t1.id;
58
+
59
+
60
+
49
61
  id | 列2 | p
50
62
 
51
63
  ----+-----+---

3

変更

2017/09/07 07:12

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -46,4 +46,18 @@
46
46
 
47
47
 
48
48
 
49
+ id | 列2 | p
50
+
51
+ ----+-----+---
52
+
53
+ 1 | あ | a
54
+
55
+ 2 | い | b
56
+
57
+ 3 | う |
58
+
59
+ 6 | か | d
60
+
61
+ (4 rows)
62
+
49
63
  ```

2

変更

2017/09/07 07:09

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -1,10 +1,10 @@
1
- Outer join 使って作成しています。
1
+ テーブルAに有るものだけテーブルBで更新っています。
2
2
 
3
3
  ```sql
4
4
 
5
- create temp table テーブルA (id int, 列2 text);
5
+ create temp table テーブルA (id int, 列2 text, P text);
6
6
 
7
- insert into テーブルA values
7
+ insert into テーブルA (id, 列2) values
8
8
 
9
9
  (1,'あ'),(2,'い'),(3,'う'),(6,'か');
10
10
 
@@ -38,28 +38,12 @@
38
38
 
39
39
 
40
40
 
41
- select t1.id, 列2, P from テーブルA t1
41
+ update テーブルA set P=t1.P
42
42
 
43
- left join テーブルB t2 using(id)
43
+ from (select * from テーブルB) t1
44
44
 
45
- order by t1.id
45
+ where テーブルA.id=t1.id;
46
-
47
- ;
48
46
 
49
47
 
50
48
 
51
- id | 列2 | p
52
-
53
- ----+-----+---
54
-
55
- 1 | あ | a
56
-
57
- 2 | い | b
58
-
59
- 3 | う |
60
-
61
- 6 | か | d
62
-
63
- (4 rows)
64
-
65
49
  ```

1

変更

2017/09/07 07:06

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -46,4 +46,20 @@
46
46
 
47
47
  ;
48
48
 
49
+
50
+
51
+ id | 列2 | p
52
+
53
+ ----+-----+---
54
+
55
+ 1 | あ | a
56
+
57
+ 2 | い | b
58
+
59
+ 3 | う |
60
+
61
+ 6 | か | d
62
+
63
+ (4 rows)
64
+
49
65
  ```