Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Conversion Rate Per City

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

Your question is Conversion Rate Per City. 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

Practo wants to compare how effectively its healthcare discovery platform converts registered users into users who make at least one booking. Write a PostgreSQL query to calculate the booking conversion rate for each user city.

Requirements

  1. Use users as the denominator population so cities with no bookings are included.
  2. Count distinct users who have at least one booking as converted users. Multiple bookings by the same user must count only once.
  3. Return the total users, converted users, and conversion rate as a percentage rounded to two decimal places.
  4. Display missing cities as Unknown and sort the output alphabetically by city.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique Practo user identifier
cityVARCHAR(100)User's registered city
bookings
ColumnTypeDescription
booking_idPKINTEGERUnique booking identifier
user_idINTEGERUser associated with the booking
Tablesusersbookings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results