Suggest Study Partners
Problem
A study app logs which practice problems each student solved on each day, and tracks existing study-partner links.
Table: solved
| Column Name | Type |
|-------------|------|
| student_id | int |
| problem_id | int |
| solve_date | date |
Each row means the student solved the problem on the given date.
Table: partners
| Column Name | Type |
|-------------|------|
| student_x | int |
| student_y | int |
(student_x, student_y) is the primary key for this table. Each row means student_x and student_y are already study partners.
Suggest student a to student b when both of the following hold:
- a and b are not already study partners (in either direction).
- a and b solved the same three or more distinct problems on the same day.
Suggestions are bidirectional: if a is suggested to b, then b must also be suggested to a. The result must contain no duplicate rows.
Return student_id and suggested_id in any order.
Tables
Example rows — the live problem includes the full dataset.
| student_id | problem_id | solve_date |
|---|---|---|
| 1 | 10 | 2021-03-15 |
| 1 | 11 | 2021-03-15 |
| 1 | 12 | 2021-03-15 |
| student_x | student_y |
|---|---|
| 1 | 2 |
Expected output
Your answer should return 6 rows with the columns student_id, suggested_id.
Starter code (SQL)
SELECT *
FROM solved;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock