質問編集履歴

1

userテーブルを追記しました

2017/09/30 11:16

投稿

yamayamak
yamayamak

スコア131

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```SQL
12
12
 
13
- select `itemID`, MAX(userID), AVG(value) as r_avg from `table_a` left join `table_b` on `table_a`.`itemID` = `table_b`.`itemID` group by `itemID`;
13
+ select `itemID`, MAX(Name), AVG(value) as r_avg from `table_a` left join `table_b` on `table_a`.`itemID` = `table_b`.`itemID` left join `table_c` on `table_a`.`UserId` = `table_c`.`UserId` group by `itemID`;
14
14
 
15
15
  ```
16
16
 
@@ -22,9 +22,9 @@
22
22
 
23
23
  |:--|:--:|:--:|
24
24
 
25
- |1|item1|userA|
25
+ |1|item1|1|
26
26
 
27
- |2|item2|userB|
27
+ |2|item2|2|
28
28
 
29
29
 
30
30
 
@@ -34,11 +34,25 @@
34
34
 
35
35
  |:--|:--:|:--:|
36
36
 
37
- |1|1|userA|
37
+ |1|1|1|
38
38
 
39
- |1|5|userB|
39
+ |1|5|2|
40
40
 
41
+ |1|3|3|
42
+
43
+
44
+
45
+ ●table_c:usersテーブル
46
+
47
+ |UserID|Name|
48
+
49
+ |:--|:--:|
50
+
51
+ |1|userA|
52
+
53
+ |2|userB|
54
+
41
- |1|3|userC|
55
+ |3|userC|
42
56
 
43
57
 
44
58