Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join With User Info

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

Your question is SQL Join With User Info. Start with the requirements and the two 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 SQL query joining the donation dataset with a user info dataset containing user_id and count launch/country details.

Asked in the Phone Screen stage. Table 1 donation data combined with user info dataset.

Requirements

  1. Join donation records to user info on user_id.
  2. Return one row per user_id with donation totals, launch count, and country count.
  3. Include users even if they have no matching donation rows.
  4. Sort by total_donations descending, then user_id ascending.

Schema

donations
ColumnTypeDescription
donation_idPKINTUnique donation record identifier
user_idINTUser who made the donation
donation_amountNUMERIC(12,2)Donation amount in dollars
donation_dateDATEDate the donation was created
user_info
ColumnTypeDescription
user_idPKINTUnique Meta user identifier
launch_countryVARCHAR(2)Country code associated with the user's launch
launch_countINTNumber of launches attributed to the user
country_countINTNumber of distinct countries associated with the user
Tablesdonationsuser_info
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results