-
Notifications
You must be signed in to change notification settings - Fork 0
/
mipt_score_view.sql
32 lines (32 loc) · 1.1 KB
/
mipt_score_view.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DROP VIEW mipt_ratings;
CREATE VIEW mipt_ratings AS
SELECT
(like_count + 1) / (mean_likes + 1) AS likes, (comment_count + 1) / (mean_comments + 1) AS comments,
mipt_follower_count * 1. / follower_count AS mipt_followers_part,
author_username, caption, mipt_follower_count, link
FROM
instagram_medias
JOIN (
SELECT
*
FROM
instagram_users
INNER JOIN (
SELECT
followee_id,
count(*) AS mipt_follower_count
FROM
instagram_followships
WHERE
followee_id IN (
SELECT
user_id
FROM
instagram_mipt_users)
GROUP BY
followee_id) mipt_followers_count
ON mipt_followers_count.followee_id = instagram_users.user_id) mipt_users
ON mipt_users.user_id = instagram_medias.author_id
where
link is not NULL AND likes is not NULL and
taken_at >= date('now', '-7 day')