質問編集履歴
1
現在の状態を記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,3 +35,37 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
お手数ですが、おわかりの方いらっしゃいましたら、具体的なコードなどのご指導をお願い致します。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
#現在のコード
|
42
|
+
|
43
|
+
以下のようなコードを現在書きました。
|
44
|
+
|
45
|
+
しかし、もう1階層分のSELECTがどのようにすれば良いのか、分からない状態です
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```PHP
|
50
|
+
|
51
|
+
$query = FruitParam::whereIn('fruit_id', function ($query){
|
52
|
+
|
53
|
+
$query->select('fruit_id')
|
54
|
+
|
55
|
+
->from('fruit_params')
|
56
|
+
|
57
|
+
->select('fruit_id', DB::raw('count(fruit_id) as count'))
|
58
|
+
|
59
|
+
->whereIn('value',['Japan', 'Aomori', 'Ehime', 'Red'])
|
60
|
+
|
61
|
+
->groupBy('fruit_id');
|
62
|
+
|
63
|
+
})->toSql();
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
```SQL
|
68
|
+
|
69
|
+
select * from "fruit_params" where "fruit_id" in (select "fruit_id", count(fruit_id) as count from "fruit_params" where "value" in (?, ?, ?, ?) group by "fruit_id")
|
70
|
+
|
71
|
+
```
|