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
SQL for Third-Last Sale
00:00
5 left

SQL for Third-Last Sale

MediumSQL · PostgreSQL

Problem

SailPoint Technologies wants to identify person records in its identity data whose sale amount exceeds the amount of the third most recent sale. Write a PostgreSQL query that returns qualifying person IDs.

The third most recent sale is determined by sold_at DESC. Use sale_id DESC as a deterministic tie-breaker when timestamps are equal.

Requirements

  1. Find the amount associated with the third most recent sale across all sales.
  2. Return each person_id with at least one sale amount greater than that amount.
  3. Exclude NULL sale amounts through the comparison and return IDs in ascending order without duplicates.

Schema

persons
ColumnTypeDescription
person_idPKINTEGERUnique person identifier
person_nameVARCHAR(100)Person display name
sales
ColumnTypeDescription
sale_idPKINTEGERUnique sale identifier
person_idINTEGERReferences persons.person_id
sale_amountNUMERIC(12,2)Sale value
sold_atTIMESTAMPSale timestamp
Tablespersonssales
Interviewer

Your question is SQL for Third-Last Sale. Start with the requirements and the two 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.