回答編集履歴
3
修正
test
CHANGED
@@ -14,34 +14,34 @@
|
|
14
14
|
|
15
15
|
```SQL
|
16
16
|
|
17
|
-
|
17
|
+
select target_id
|
18
18
|
|
19
|
-
|
19
|
+
, max(
|
20
20
|
|
21
|
-
|
21
|
+
case when action_name='follow' then action_date end
|
22
22
|
|
23
|
-
|
23
|
+
) as follow_date
|
24
24
|
|
25
|
-
|
25
|
+
, max(
|
26
26
|
|
27
27
|
case when action_name='favorite' then action_date end
|
28
28
|
|
29
29
|
) as favorite_date
|
30
30
|
|
31
|
-
|
31
|
+
from action_table user
|
32
32
|
|
33
|
-
|
33
|
+
where target_type='user' and action_name in ('favorite', 'follow')
|
34
34
|
|
35
|
-
|
35
|
+
and exists(
|
36
36
|
|
37
|
-
|
37
|
+
select 1 from action_table
|
38
38
|
|
39
|
-
|
39
|
+
where target_id =user.target_id and action_name='favorite'
|
40
40
|
|
41
|
-
|
41
|
+
)
|
42
42
|
|
43
|
-
|
43
|
+
and actor_id=1
|
44
44
|
|
45
|
-
|
45
|
+
group by target_id
|
46
46
|
|
47
47
|
```
|
2
追記
test
CHANGED
@@ -3,3 +3,45 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
前回の回答の際「理解できていないままで、適用してしまうと後が大変ですよ。」とコメントしましたが、まさにこの事です。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
追記
|
10
|
+
|
11
|
+
--
|
12
|
+
|
13
|
+
あてずっぽうですけど、メイン部分のSQLは多分こんな感じ
|
14
|
+
|
15
|
+
```SQL
|
16
|
+
|
17
|
+
select target_id
|
18
|
+
|
19
|
+
, max(
|
20
|
+
|
21
|
+
case when action_name='follow' then action_date end
|
22
|
+
|
23
|
+
) as follow_date
|
24
|
+
|
25
|
+
, max(
|
26
|
+
|
27
|
+
case when action_name='favorite' then action_date end
|
28
|
+
|
29
|
+
) as favorite_date
|
30
|
+
|
31
|
+
from action_table
|
32
|
+
|
33
|
+
where actor_id=1
|
34
|
+
|
35
|
+
and target_id not in(
|
36
|
+
|
37
|
+
select actor_id
|
38
|
+
|
39
|
+
from action_table
|
40
|
+
|
41
|
+
where target_type='user' and action_name='block' and target_id=1
|
42
|
+
|
43
|
+
)
|
44
|
+
|
45
|
+
group by target_id
|
46
|
+
|
47
|
+
```
|
1
追記
test
CHANGED
@@ -1 +1,5 @@
|
|
1
1
|
`his_favorite`の部分は以前回答をしたものをそのまま流用されているようですが、その際のテーブルとは仕様の違うテーブルですので、適宜変更しなければ求める結果にはなりません。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
前回の回答の際「理解できていないままで、適用してしまうと後が大変ですよ。」とコメントしましたが、まさにこの事です。
|