-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interviews.sql
35 lines (34 loc) · 1.09 KB
/
Interviews.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
33
34
35
'''
Problem Statement: https://www.hackerrank.com/challenges/interviews/problem
@Coded by TSG, 2020
'''
SELECT CON.CONTEST_ID,
CON.HACKER_ID,
CON.NAME,
SUM(TOTAL_SUBMISSIONS),
SUM(TOTAL_ACCEPTED_SUBMISSIONS),
SUM(TOTAL_VIEWS),
SUM(TOTAL_UNIQUE_VIEWS)
FROM CONTESTS CON
JOIN COLLEGES COL ON CON.CONTEST_ID = COL.CONTEST_ID
JOIN CHALLENGES CHA ON COL.COLLEGE_ID = CHA.COLLEGE_ID
LEFT JOIN
(SELECT CHALLENGE_ID,
SUM(TOTAL_VIEWS) AS TOTAL_VIEWS,
SUM(TOTAL_UNIQUE_VIEWS) AS TOTAL_UNIQUE_VIEWS
FROM VIEW_STATS
GROUP BY CHALLENGE_ID) VS ON CHA.CHALLENGE_ID = VS.CHALLENGE_ID
LEFT JOIN
(SELECT CHALLENGE_ID,
SUM(TOTAL_SUBMISSIONS) AS TOTAL_SUBMISSIONS,
SUM(TOTAL_ACCEPTED_SUBMISSIONS) AS TOTAL_ACCEPTED_SUBMISSIONS
FROM SUBMISSION_STATS
GROUP BY CHALLENGE_ID) SS ON CHA.CHALLENGE_ID = SS.CHALLENGE_ID
GROUP BY CON.CONTEST_ID,
CON.HACKER_ID,
CON.NAME
HAVING SUM(TOTAL_SUBMISSIONS) != 0
OR SUM(TOTAL_ACCEPTED_SUBMISSIONS) != 0
OR SUM(TOTAL_VIEWS) != 0
OR SUM(TOTAL_UNIQUE_VIEWS) != 0
ORDER BY CONTEST_ID;