回答編集履歴

6

追記

2020/02/07 11:54

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  where target_type='user' and action_name in ('favorite', 'follow') -- blockは除外
24
24
 
25
- and exists( -- いいね('favorite')をしていないユーザはは除く
25
+ and exists( -- いいね('favorite')をしていユーザ
26
26
 
27
27
  select 1 from action_table
28
28
 

5

追記

2020/02/07 11:54

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  where target_type='user' and action_name in ('favorite', 'follow') -- blockは除外
24
24
 
25
- and exists(
25
+ and exists( -- いいね('favorite')をしていないユーザはは除く
26
26
 
27
27
  select 1 from action_table
28
28
 

4

推敲

2020/02/07 11:53

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  from action_table user
22
22
 
23
- where target_type='user' and action_name in ('favorite', 'follow')
23
+ where target_type='user' and action_name in ('favorite', 'follow') -- blockは除外
24
24
 
25
25
  and exists(
26
26
 

3

追記

2020/02/07 05:17

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -1,3 +1,7 @@
1
+ group byで指定している項目以外は、集計(max()とか、count()とか)でないと通常はエラーです。
2
+
3
+ mysqlでは設定により、集計を指定しなくても忖度しますがその値は不定(保証されない)です。
4
+
1
5
  ```SQL
2
6
 
3
7
  select target_id

2

推敲

2020/02/07 05:14

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -10,9 +10,9 @@
10
10
 
11
11
  , max(
12
12
 
13
- case when action_name='favorite' then action_date end
13
+ case when action_name='favorite' then action_date end
14
14
 
15
- ) as favorite_date
15
+ ) as favorite_date
16
16
 
17
17
  from action_table user
18
18
 

1

追記

2020/02/07 05:09

投稿

sazi
sazi

スコア25206

test CHANGED
@@ -31,3 +31,5 @@
31
31
  group by target_id
32
32
 
33
33
  ```
34
+
35
+ ※2も取得する必要があるなら、exsists()の条件を外してください。