UNION ALL
to combine gold_medal
, silver_medal
, and bronze_medal
into a single column named user
along with their corresponding contest_id
.ROW_NUMBER()
window function partitioned by user
and ordered by contest_id
to assign a rank to each medal.contest_id
and the rank to identify consecutive medals.user
and the calculated difference to find users with three or more consecutive medals.gold_medal
to find users with three or more gold medals.UNION ALL
to combine the results from steps 4 and 5.Users
table to get the name
and mail
of the interview candidates.DISTINCT
to remove any duplicates resulting from the union operation.erDiagram Contests { int contest_id PK int gold_medal int silver_medal int bronze_medal } Users { int user_id PK varchar mail varchar name } Contests ||--o{ Users : "contains"