Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Servers by Abuse Report Ratio

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rank Servers by Abuse Report Ratio. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a PostgreSQL query to find Discord servers with the highest ratio of abuse reports to active users. Return server_id, abuse report count, active user count, total bans, and the ratio. Only include servers with at least 2 active users, and sort by ratio descending, then server_id ascending.

Schema

ColumnTypeDescription
member_id
server_id
user_id
is_active
joined_at
ColumnTypeDescription
report_id
server_id
reporter_user_id
reported_user_id
report_type
created_at
ColumnTypeDescription
ban_id
server_id
banned_user_id
banned_at

What to watch for

  • Count only rows where report_type = 'abuse'.
  • Treat a user as active only when is_active = true.
  • Servers with no bans should still appear with 0 bans.
  • Avoid overcounting by aggregating before joining.
Tablesserver_membersuser_reportsserver_bans
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results