Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Optimize International Booking Aggregation
00:00
5 left

Optimize International Booking Aggregation

HardSQL · PostgreSQL

Problem

Optimize a slow-running SQL query that aggregates daily booking data across multiple international markets.

Write a PostgreSQL query that returns daily confirmed or completed booking performance for January 1 through January 3, 2025. Convert each booking amount from local currency to USD using the market exchange rate, then calculate the previous reported day's GBV and percentage change for each market. Bookings with NULL dates or listing IDs are ignored. NULL booking amounts remain counted but contribute nothing to GBV.

Output

  1. One row per market and reporting date with columns market_code, booking_date, booking_count, daily_gbv_usd, prior_day_gbv_usd, and gbv_change_percent
  2. Include only markets with qualifying bookings; the first reported day for a market has NULL prior-day values
  3. Sort by market_code, then booking_date ascending

Schema

bookings
ColumnTypeDescription
booking_idPKINTUnique booking identifier
listing_idINTListing associated with the booking
booked_atDATEBooking date
statusVARCHAR(30)Booking lifecycle status
amount_localNUMERIC(14,2)Booking amount in local currency
listings
ColumnTypeDescription
listing_idPKINTUnique listing identifier
market_idINTMarket containing the listing
listing_nameVARCHAR(100)Listing display name
markets
ColumnTypeDescription
market_idPKINTUnique market identifier
market_codeVARCHAR(8)Market code
local_to_usdNUMERIC(10,6)Conversion rate from local currency to USD
Tablesbookingslistingsmarkets
Interviewer

Your question is Optimize International Booking Aggregation. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.