teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

Controllerの誤りを修正

2017/09/30 03:42

投稿

yamayamak
yamayamak

スコア131

title CHANGED
File without changes
body CHANGED
@@ -15,9 +15,7 @@
15
15
  $join->on('table_a.userid', '=', 'table_b.userid')
16
16
  ->avg('data');
17
17
  });
18
- $result = $result ->orderBy('table_a.updated_at', 'desc')
19
- ->take(10)
20
- ->get();
18
+ $result = $result ->get();
21
19
  ```
22
20
 
23
21
 

2

テーブル追加

2017/09/30 03:42

投稿

yamayamak
yamayamak

スコア131

title CHANGED
File without changes
body CHANGED
@@ -25,4 +25,21 @@
25
25
  "message": "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to you
26
26
  r MySQL server version for the right syntax to use near 'on `table_a`.`userid` = ?' at line 1 (SQL: select avg(`data`) as aggregate on `table_a`.`
27
27
  userid` = table_b.userid)",
28
- ```
28
+ ```
29
+
30
+ ●table_a:ユーザテーブル
31
+ |userID|Name|
32
+ |:--|:--:|
33
+ |1|userA|
34
+ |2|userB|
35
+
36
+ ●table_b:評価テーブル
37
+ |userID|Data|
38
+ |:--|:--:|
39
+ |1|1|
40
+ |1|5|
41
+
42
+
43
+ ●期待するクエリ回答
44
+ 1,userA,3
45
+ 2,userB,null

1

エラーも追記しました。

2017/09/30 02:26

投稿

yamayamak
yamayamak

スコア131

title CHANGED
File without changes
body CHANGED
@@ -15,7 +15,14 @@
15
15
  $join->on('table_a.userid', '=', 'table_b.userid')
16
16
  ->avg('data');
17
17
  });
18
- $listpart = $listpart->orderBy('table_a.updated_at', 'desc')
18
+ $result = $result ->orderBy('table_a.updated_at', 'desc')
19
19
  ->take(10)
20
20
  ->get();
21
+ ```
22
+
23
+
24
+ ```php
25
+ "message": "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to you
26
+ r MySQL server version for the right syntax to use near 'on `table_a`.`userid` = ?' at line 1 (SQL: select avg(`data`) as aggregate on `table_a`.`
27
+ userid` = table_b.userid)",
21
28
  ```