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
Window Functions Data Retrieval
00:00
5 left

Window Functions Data Retrieval

MediumSQL · PostgreSQL

Problem

Ancestry wants to understand which paid members had the most productive sessions in Ancestry Record Search during January 2025. Write a PostgreSQL query using a window function to return each paid member's best qualifying session, including paid members with no qualifying session.

Requirements

  1. Consider only members with a Plus or Pro subscription.
  2. Include only completed sessions on the Record Search surface from 2025-01-01 inclusive through 2025-02-01 exclusive.
  3. Rank each member's sessions by result_count descending, then by started_at descending to break ties, and return rank 1 for each member.
  4. Preserve paid members without a qualifying session, showing NULL session fields. Order the final results by member_id.

Schema

members
ColumnTypeDescription
member_idPKINTEGERUnique Ancestry member identifier
display_nameVARCHAR(100)Member display name
subscription_tierVARCHAR(20)Current membership tier
country_codeVARCHAR(2)Two-letter member country code
search_sessions
ColumnTypeDescription
session_idPKINTEGERUnique search session identifier
member_idINTEGERMember associated with the session
started_atTIMESTAMPTimestamp when the session began
search_surfaceVARCHAR(40)Ancestry product surface used
result_countINTEGERNumber of results returned by the session
statusVARCHAR(20)Session completion state
Tablesmemberssearch_sessions
Interviewer

Your question is Window Functions Data Retrieval. 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.