回答編集履歴
3
追記しました
answer
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
1
|
+
######修正分
|
2
|
-
commentsで絞って、postで絞って、…と。
|
3
2
|
|
3
|
+
サブクエリで遅いというのは、こんな感じにした場合ことでしょうか?
|
4
|
+
SQLがあると、アドバイスがつきやすいかもしれません。
|
5
|
+
|
4
6
|
```sql
|
5
7
|
select ...
|
6
8
|
from users
|
7
9
|
join posts
|
8
10
|
on ...
|
11
|
+
join (select ... // fooの数とコメントの数が一致していれば、postsとcommentsをjoinできるような要素を出力する
|
12
|
+
from comments
|
13
|
+
goup by postid) as filterdComments
|
14
|
+
on ...
|
9
15
|
join comments
|
10
|
-
on
|
16
|
+
on ...
|
11
17
|
```
|
2
微修正
answer
CHANGED
@@ -7,5 +7,5 @@
|
|
7
7
|
join posts
|
8
8
|
on ...
|
9
9
|
join comments
|
10
|
-
on (... and xxx = hoge)
|
10
|
+
on (... and xxx = hoge) --※xxx = hoge はそれらしい条件に置き換えてください
|
11
11
|
```
|
1
まちがえたので修正~
answer
CHANGED
@@ -4,13 +4,8 @@
|
|
4
4
|
```sql
|
5
5
|
select ...
|
6
6
|
from users
|
7
|
-
join (select ...
|
8
|
-
|
7
|
+
join posts
|
9
|
-
join (select ...
|
10
|
-
from comments
|
11
|
-
where ...)
|
12
|
-
on ...
|
13
|
-
where ...)
|
14
8
|
on ...
|
15
|
-
|
9
|
+
join comments
|
10
|
+
on (... and xxx = hoge)
|
16
11
|
```
|