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 and PySpark Basics
00:00
5 left

SQL and PySpark Basics

HardSQL · PostgreSQL

Problem

Explain how you would use SQL and PySpark to transform raw data into an analysis-ready dataset.

Use the supplied raw event and customer tables. Prepare valid, deduplicated customer activity metrics, excluding inactive customers, malformed contact values, unsupported event types, and unmatched customer records. The SQL result should represent the type of analysis-ready output you would also produce with PySpark.

Output

  1. One row per active customer and activity date
  2. Columns: customer_id, customer_name, activity_date, total_events, transaction_events, net_revenue
  3. Include only dates with valid events, ordered by customer_id, then activity_date

Schema

raw_events
ColumnTypeDescription
event_idINTBusiness identifier for an event, which may be duplicated across ingestions
customer_idINTCustomer associated with the event
emailVARCHAR(255)Raw customer email value
event_typeVARCHAR(30)Raw event category
event_timestampTIMESTAMPTime when the event occurred
amountNUMERIC(12,2)Event amount
ingested_atTIMESTAMPTime when the record was ingested
source_systemVARCHAR(40)System that supplied the raw record
customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(120)Customer display name
is_activeBOOLEANWhether the customer is currently active
segmentVARCHAR(40)Customer segment
Tablesraw_eventscustomers
Interviewer

Your question is SQL and PySpark Basics. 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.