Interview Query

Comment Upvotes

Upvote
11
Downvote
Save
Mark Completed
Have you seen this question before?

We’re given three tables representing a forum of users and their comments on posts.

Write a query to get the top three users that got the most upvotes on their comments written in 2020. 

Note: Do not count deleted comments and upvotes by users on their own comments

Example:

Input:

users table

Column Type
id INTEGER
created_at DATETIME
username VARCHAR

comments table

Columns Type
id INTEGER
created_at datetime
post_id INTEGER
user_id INTEGER
is_deleted BOOLEAN

comment_votes table

Column Type
id INTEGER
created_at DATETIME
user_id INTEGER
comment_id INTEGER
is_upvote BOOLEAN

Output:

Column Type
id INTEGER
username VARCHAR
upvotes INTEGER
Next question: Popular Apple Actions
.....
Loading editor
Use Shift + Enter to run

Comments

Loading comments