HARDVerified Real Interview• Analytics Engineer
Customer Peak Spending Day (Chained CTE)
Verified Source:Public Candidate Interview Report
Amazon Prime analytics wants to identify each customer's single highest spending calendar day.
Write a SQL query using Common Table Expressions (WITH) to find each customer's peak spend day.
Return customer_id, order_date, and daily_spend.
If a customer tied their peak spend across multiple days, output the most recent date.
Sort by daily_spend descending, then customer_id ascending.
Tables:
orders(order_idINT,customer_idINT,order_dateDATE,amountDECIMAL)
Execution Sandbox:
Your query executes inside an isolated in-memory PostgreSQL engine (PGlite WebAssembly). You have full access to standard PostgreSQL aggregations, window functions, and CTEs.
Standard SQL (ANSI)|Ln 1, Col 1(7 lines, 120 chars)
Tab Indent⌘↵ Run Query
Ready to execute. Press Run (⌘+Enter)
Write your query and click “Run” or press ⌘+Enter to inspect output.