Solve SQL and Python OA tasks
WayfairData Scientist · Online AssessmentLast updated
This question evaluates SQL and pandas data-manipulation skills, including joined aggregations over date windows, handling of missing values with median imputation, and multi-criteria sorting and tie-breaking.
Complete the following two online-assessment tasks.
Task A — SQL
You are given two tables:
customer
customer_idINTcustomer_nameVARCHARpurchase_idVARCHAR
purchase
idVARCHARpurchase_priceDECIMAL(10,2)purchase_dateDATE
customer.purchase_id joins to purchase.id.
Based on the sample in the original prompt, interpret "the earliest 10 years" as the historical 10-year window that starts on the minimum purchase_date in the purchase table and ends just before MIN(purchase_date) + INTERVAL '10 years'. Assume purchase_date is stored as a DATE in UTC.
Write a SQL query to return the customer(s) whose purchase_price is the highest within that earliest 10-year window. If multiple customers tie for the highest qualifying price, return all of them.
Required output columns:
customer_namehighest_purchase_price
Task B — Python
You are given a pandas DataFrame students with schema:
student_idINTmath_scoreFLOAT NULLenglish_scoreFLOAT NULLphysics_scoreFLOAT NULL
Write a Python function that returns the top students after the following processing steps:
- Remove any student who is missing scores in at least two subjects.
- For the remaining students, fill each missing subject score with the median of that subject, computed over the remaining non-null rows.
- Sort the cleaned table by
math_scoredescending, thenphysics_scoredescending. If additional tie-breaking is needed, sort bystudent_idascending. - Return the top 5 rows. If fewer than 5 students remain, return all remaining rows.
Return the full cleaned rows for the selected students.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.