回答編集履歴

1

変更

2020/02/01 12:19

投稿

sazi
sazi

スコア25173

test CHANGED
@@ -16,33 +16,37 @@
16
16
 
17
17
  from (
18
18
 
19
- select 'main' as action_name, actor_id as user_id, Null as follow_date, Null as favorite_date
19
+ select follow.actor_id
20
20
 
21
- from action_datas
21
+ , max(
22
22
 
23
- where target_type ='user' and actor_id=1 and action_name='follow'
23
+ case when action.action_name='follow' then action.action_date end
24
24
 
25
- union all
25
+ ) as follow_date
26
26
 
27
- select action_name, target_id, action_date, Null
27
+ , max(
28
28
 
29
- from action_datas
29
+ case when action.action_name='favorite' then action.action_date end
30
30
 
31
- where target_type ='user' and actor_id=1 and action_name='follow'
31
+ ) as favorite_date
32
32
 
33
- union all
33
+ from action_datas follow
34
34
 
35
- select action_name, target_id, Null, action_date
35
+ left join action_datas action
36
36
 
37
- from action_datas
37
+ on follow.actor_id=action.target_id
38
38
 
39
+ and action.actor_id=1 and action.target_type='user'
40
+
39
- where target_type ='user' and actor_id=1 and action_name='favorite'
41
+ where follow.target_type='thread' and follow.target_id=20
42
+
43
+ group by follow.actor_id
40
44
 
41
45
  ) thread_follower
42
46
 
43
47
  left join main_datas main
44
48
 
45
- on thread_follower.user_id=main.main_id
49
+ on thread_follower.actor_id=main.main_id
46
50
 
47
51
  left join sub_datas age
48
52