Skip to content

Commit fe30526

Browse files
authored
Create 15_days_of_learning_sql.sql
1 parent b935cfb commit fe30526

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Write a query to print total number of unique hackers who made at least 1
3+
submission each day (starting on the first day of the contest), and find
4+
the hacker_id and name of the hacker who made maximum number of submissions
5+
each day. If more than one such hacker has a maximum number of submissions,
6+
print the lowest hacker_id. The query should
7+
print this information for each day of the contest, sorted by the date.
8+
9+
*/
10+
11+
12+
-- really stupid problem - i was sitting on this one for so long cuz it's badly worded - just looked up the solution
13+
select
14+
submission_date ,
15+
16+
( SELECT COUNT(distinct hacker_id)
17+
FROM Submissions s2
18+
WHERE s2.submission_date = s1.submission_date AND (SELECT COUNT(distinct s3.submission_date) FROM Submissions s3 WHERE s3.hacker_id = s2.hacker_id AND s3.submission_date < s1.submission_date) = dateDIFF(s1.submission_date , '2016-03-01')) ,
19+
20+
(select hacker_id from submissions s2 where s2.submission_date = s1.submission_date
21+
group by hacker_id order by count(submission_id) desc , hacker_id limit 1) as shit,
22+
(select name from hackers where hacker_id = shit)
23+
from
24+
(select distinct submission_date from submissions) s1
25+
group by submission_date

0 commit comments

Comments
 (0)