Loading content...
A streaming analytics platform stores films, reviewers, and scoring events in three relational tables:
movies(movie_id, title)
users(user_id, name)
movie_rating(movie_id, user_id, rating, created_at)
Your task is to return two leaderboard answers in one output column named results:
Output requirements:
Supported submission environments:
movies:
| movie_id | title |
|----------|------------------|
| 1 | Nebula Run |
| 2 | Arctic Tale 2 |
| 3 | Night Jester |
users:
| user_id | name |
|---------|--------|
| 1 | Damon |
| 2 | Monica |
| 3 | Maris |
| 4 | Jules |
movie_rating:
| movie_id | user_id | rating | created_at |
|----------|---------|--------|------------|
| 1 | 1 | 3 | 2020-01-12 |
| 1 | 2 | 4 | 2020-02-11 |
| 1 | 3 | 2 | 2020-02-12 |
| 1 | 4 | 1 | 2020-01-01 |
| 2 | 1 | 5 | 2020-02-17 |
| 2 | 2 | 2 | 2020-02-01 |
| 2 | 3 | 2 | 2020-03-01 |
| 3 | 1 | 3 | 2020-02-22 |
| 3 | 2 | 4 | 2020-02-25 |[
{"results":"Damon"},
{"results":"Arctic Tale 2"}
]Damon and Monica both submitted 3 ratings, so Damon wins by lexicographic tie-break. In February 2020, Arctic Tale 2 and Night Jester both average 3.5, so Arctic Tale 2 wins by title tie-break.
movies:
| movie_id | title |
|----------|------------|
| 10 | Solo Cut |
users:
| user_id | name |
|---------|------|
| 7 | Ari |
movie_rating:
| movie_id | user_id | rating | created_at |
|----------|---------|--------|------------|
| 10 | 7 | 4 | 2020-02-10 |[
{"results":"Ari"},
{"results":"Solo Cut"}
]Only one reviewer and one February rating exist, so both leaders are uniquely determined.
movies:
| movie_id | title |
|----------|--------------|
| 20 | Alpha Frame |
| 21 | Beta Frame |
users:
| user_id | name |
|---------|-------|
| 30 | Alice |
| 31 | Aaron |
| 32 | Milo |
movie_rating:
| movie_id | user_id | rating | created_at |
|----------|---------|--------|------------|
| 20 | 30 | 5 | 2020-02-01 |
| 21 | 30 | 1 | 2020-01-01 |
| 20 | 31 | 4 | 2020-02-02 |
| 21 | 31 | 2 | 2020-03-01 |
| 20 | 32 | 3 | 2020-02-03 |[
{"results":"Aaron"},
{"results":"Alpha Frame"}
]Alice and Aaron tie in total rating count, so Aaron wins by name ordering. In February, Alpha Frame has the highest average and is selected.
Constraints