回答編集履歴

2

追記

2018/10/27 03:40

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -25,3 +25,27 @@
25
25
  )
26
26
 
27
27
  ```
28
+
29
+ 追記
30
+
31
+ --
32
+
33
+ users の行を求めたいのだから、keyのレベルを合わせるのにはサブクエリーが必須になるんですよね。
34
+
35
+ 一応別パターン
36
+
37
+ ```SQL
38
+
39
+ select *
40
+
41
+ from users inner join (
42
+
43
+ select user_id from posts inner join comments on posts.id=comments.post_id
44
+
45
+ group by user_id
46
+
47
+ having count(*)=sum(case when comments.body='foo' then 1 else 0 end)
48
+
49
+ ) cond on cond.user_id=users.id
50
+
51
+ ```

1

修正

2018/10/27 03:40

投稿

sazi
sazi

スコア25195

test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  select 1 from posts inner join comments on posts.id=comments.post_id
14
14
 
15
- where posts.user_id=users.id and comments.body='foo'
15
+ where posts.user_id=users.id and comments.body<>'foo'
16
16
 
17
17
  )
18
18