Approach
Relational aggregation
For Find Interview Candidates, the query transforms and combines relational rows, then filters or aggregates them into the requested result.
- Identify the source rows and join keys.
- Apply filters before aggregation when possible.
- Group, rank, or project the final columns required by the result.
Code notes
- 37 lines of SQL from the credited upstream file 1811.sql.
- The implementation keeps its working state in language-native values and containers.
- No explicit loop blocks detected.
Complexity
Review join cardinality, grouping keys, and available indexes when estimating query cost.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1WITH2 UserToContest AS (3 SELECT gold_medal AS user_id, contest_id FROM Contests4 UNION ALL5 SELECT silver_medal AS user_id, contest_id FROM Contests6 UNION ALL7 SELECT bronze_medal AS user_id, contest_id FROM Contests8 ),9 UserToContestWithGroupId AS (10 SELECT11 user_id,12 contest_id - ROW_NUMBER() OVER(13 PARTITION BY user_id14 ORDER BY contest_id15 ) AS group_id16 FROM UserToContest17 ),18 CandidateUserIds AS (19 20 SELECT user_id21 FROM UserToContestWithGroupId22 GROUP BY user_id, group_id23 HAVING COUNT(*) >= 324 UNION DISTINCT25 26 SELECT gold_medal AS user_id27 FROM Contests28 GROUP BY user_id29 HAVING COUNT(*) >= 330 )31SELECT32 Users.name,33 Users.mail34FROM CandidateUserIds35INNER JOIN Users36 USING (user_id);37