-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathinterviews.sql
More file actions
54 lines (52 loc) · 1.21 KB
/
interviews.sql
File metadata and controls
54 lines (52 loc) · 1.21 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Interviews
-- https://www.hackerrank.com/challenges/interviews/problem
WITH STATS1 AS (
SELECT
challenge_id
,SUM(ss.total_submissions) AS total_submissions
,SUM(ss.total_accepted_submissions) AS total_accepted_submissions
FROM
CHALLENGES ch
LEFT JOIN SUBMISSION_STATS ss
USING(challenge_id)
GROUP BY
challenge_id
)
, STATS2 AS (
SELECT
challenge_id
,total_submissions
,total_accepted_submissions
,SUM(vs.total_views) AS total_views
,SUM(vs.total_unique_views) AS total_unique_views
FROM
STATS1
LEFT JOIN VIEW_STATS vs
USING(challenge_id)
GROUP BY
challenge_id
,total_submissions
,total_accepted_submissions
)
SELECT
contest_id
, c.hacker_id
, c.name
, SUM(s2.total_submissions) AS total_submissions
, SUM(s2.total_accepted_submissions) AS total_accepted_submissions
, SUM(s2.total_views) AS total_views
, SUM(s2.total_unique_views) AS total_unique_views
FROM
CONTESTS c
JOIN COLLEGES co
USING(contest_id)
JOIN CHALLENGES ch
USING(college_id)
JOIN STATS2 s2
ON ch.challenge_id = s2.challenge_id
GROUP BY
contest_id
, c.hacker_id
, c.name
ORDER BY
contest_id;