SQL interview questions · By company
Amazon SQL interview questions
For business intelligence engineer and data analyst roles: what candidates report, and how to practice for it.
SQLRep isn't affiliated with or endorsed by Amazon. This guide summarizes public candidate reports and prep guides (sources below, checked November 2026). The practice questions are original, written in the reported style; they aren't Amazon's actual questions. Processes change, so confirm details with your recruiter.
What candidates report about the process
- Candidates report a phone screen with SQL, then a loop where several rounds mix technical and behavioral questions.
- Leadership Principles carry a lot of weight: some rounds are reported as purely behavioral.
- One candidate reports five SQL questions on a shared set of tables in a single round.
SQL topics that come up
- LAG and LEAD: time between orders, comparing a row with the next one
- Top N per category with window ranking
- Churn and retention defined from order activity
- Self-joins and CASE logic, plus INNER versus LEFT JOIN
- Data modeling basics: fact versus dimension tables
Practice the reported patterns
Each one runs in real PostgreSQL in your browser, with feedback on what's wrong.
- Average days between a customer's ordersFor every customer with at least two completed orders, return name, completed_orders and avg_gap_days (the average number of days between consecutive completed orders, rounded to 1 decimal). Cancelled orders don't count. Sort by avg_gap_days, then name.Pattern: LAG · date subtraction · AVG over a window resultMediumPro
- Next order bigger than this oneFor every completed order where the same customer's next completed order (by order_date) has a strictly larger amount, return name, order_id, order_date, amount, next_amount and increase (next_amount - amount). Sort by order_date, then order_id.Pattern: LEAD · PARTITION BY · filter in an outer queryEasyPro
- Top 3 products per category by units, ties keptUsing completed orders only, total each product's units_sold (sum of quantity). Return category, product (product name), units_sold and units_rank (RANK within the category, most units first: ties share a rank and the next rank is skipped) for every product with units_rank 3 or better. Sort by category, units_rank, then product.Pattern: RANK vs DENSE_RANK vs ROW_NUMBER · PARTITION BYMediumPro
- Monthly customer churn from ordersFor each month from 2024-02 to 2024-06, return month (YYYY-MM), active_last_month (customers active in the previous month), churned (of those, customers not active this month) and churn_rate_pct (churned as a % of active_last_month, rounded to 1 decimal). Sort by month.Pattern: Monthly activity sets · LEFT JOIN anti-match · zero-churn monthsHardPro
- Same product bought two months runningReturn one row per customer, product and pair of consecutive months in which that customer bought that product: name, product (product name), first_month and second_month (both YYYY-MM). Sort by name, product, then first_month.Pattern: Self-join on month + 1 · DISTINCT before joining · year boundariesHardPro
- Days until next orderFor every completed order, return customer_id, order_id, order_date and days_to_next (whole days until the same customer's next completed order; NULL for their last one). Sort by customer_id, order_date.Pattern: LEAD() · PARTITION BYMediumPro
- Top 3 products per categoryRevenue is quantity * unit_price over completed orders (order lines without a product are ignored). Return category, product (product name), revenue and revenue_rank (DENSE_RANK of revenue within the category, highest first) for every product whose revenue_rank is 3 or better. Sort by category, revenue_rank, then product.Pattern: DENSE_RANK · PARTITION BY · tiesMediumPro
- Monthly churn rateUsing app_opens, for February, March and April 2024 return month (YYYY-MM), churned_users (users active in the previous month with no app opens this month) and churn_rate_pct (churned_users as a percentage of the previous month's active users, rounded to 1 decimal). Oldest first.Pattern: Anti-join across months · churnHardPro
- Consecutive-day loginsReturn the distinct user_id of every user with logins on two consecutive days. Sort by user_id.Pattern: LAG() · date arithmeticMediumPro
- Earning more than their managerReturn employee, employee_salary, manager and manager_salary for every employee who earns more than their manager. Sort by employee.Pattern: Self-joinMediumPro
- Second order within 30 daysNumber each customer's completed orders by ordered_on (then id). Return name, first_order_on, second_order_on and days_between (second minus first, in days) for every customer whose second completed order came at most 30 days after their first (exactly 30 counts). Sort by name.Pattern: ROW_NUMBER · self-join on rn = 1 and rn = 2 · date differenceHardPro
Tip: Expect follow-ups that change the definition (for example 'now count churn by week'). Write queries that are easy to adjust.
Sources
- LeetCode Discuss: Amazon BIE interview experience
- Prepfully: Amazon BIE interview guide
- Exponent: Amazon BIE interview
- VisualCV: Amazon SQL interview questions
Amazon is a trademark of its owner, used here only to identify the company the reports are about.