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
End-to-End PySpark Script
00:00
5 left

End-to-End PySpark Script

MediumSQL · PostgreSQL

Problem

Write an end-to-end PySpark script that produces a given output table from the input data.

Asked in the Round 1 stage. Two such questions were asked in round 1, per thread 1uv9sob.

Output

  1. Return one row per customer with customer_id, customer_name, customer_segment, completed_transaction_count, completed_amount, and activity_status.
  2. Include only transactions with status COMPLETED from 2025-01-01 through 2025-03-31. Include customers with no qualifying transactions.
  3. Sort by completed_amount descending, then customer_id ascending. completed_amount must be zero when no qualifying amount exists.

Schema

customers
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
customer_nameVARCHAR(100)Customer display name
customer_segmentVARCHAR(60)Customer segment classification
transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
customer_idINTEGERCustomer associated with the transaction
amountNUMERIC(14,2)Transaction amount
transaction_dateDATEDate the transaction occurred
statusVARCHAR(60)Transaction processing status
Tablescustomerstransactions
Interviewer

Your question is End-to-End PySpark Script. 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.