SQL Question Bank — Master Tracking File
💡 Interview Tip
HOW TO USE THIS FILE:
- This is the SINGLE SOURCE OF TRUTH for all SQL interview questions
- Every question has a Q# (never change old numbers, only append new ones)
- Pattern# maps to the 15 patterns in the prep files
- To ADD new questions: append rows at the bottom with the next Q#
- To CLASSIFY a question you received in interview: match to the Pattern column
PATTERN REFERENCE (Quick Lookup)
| P# | Pattern Name | Key SQL |
|---|---|---|
| P1 | Ranking / Top-N Per Group | ROW_NUMBER, RANK, DENSE_RANK + PARTITION BY |
| P2 | Running Totals / Cumulative | SUM() OVER (ORDER BY) |
| P3 | LAG / LEAD — Row-over-Row | LAG(), LEAD() |
| P4 | Gaps & Islands | date - ROW_NUMBER() island grouping |
| P5 | Sessionization | LAG() gap detection + cumulative SUM as session_id |
| P6 | Deduplication | ROW_NUMBER() PARTITION BY, keep rank = 1 |
| P7 | Self-Join | Same table aliased twice |
| P8 | Cross Join — Combinations | CROSS JOIN for Cartesian product |
| P9 | Market Basket / Co-occurrence | Self-join on order_id, item1 < item2 |
| P10 | Conditional Aggregation / Pivot | SUM(CASE WHEN ...) |
| P11 | Cohort / Retention Analysis | MIN(event_date) as cohort + date offset |
| P12 | Date Arithmetic | DATEDIFF, DATE_TRUNC, INTERVAL |
| P13 | Recursive CTE | WITH RECURSIVE anchor + recursive step |
| P14 | Median / Percentile | PERCENTILE_CONT or ROW_NUMBER median trick |
| P15 | Funnel Analysis | Multi-stage COUNT DISTINCT + conversion rate |
FULL QUESTION BANK
| Q# | Question | Company | Pattern | Difficulty | Solved? |
|---|---|---|---|---|---|
| Q01 | Top 2 highest-grossing products within each category in 2022 | Amazon | P1 | Medium | ✓ |
| Q02 | Top 3 salaries in each department | FAANG Classic | P1 | Medium | ✓ |
| Q03 | Email activity rank per user (sent + received + spam, dense ranked) | P1 | Medium | ✓ | |
| Q04 | Top 2 users per company with most calls (maintain ties) | RingCentral | P1 | Medium | |
| Q05 | Most-used vehicle type in past year (excluding cancelled rides) | Uber | P1 | Easy-Med | |
| Q06 | Olympic swimmers who won ONLY gold medals — count golds each | Amazon | P1 | Medium | |
| Q07 | Nominee who won the most Oscars | Netflix | P1 | Easy | |
| Q08 | Top 10 users by total distance across all rides | Lyft | P1 | Medium | |
| Q09 | Top 5 product pairs most frequently purchased together | Interview Query | P1+P9 | Hard | |
| Q10 | Top 3 departments by average salary | Classic | P1 | Easy | |
| Q11 | Cumulative merchant transaction balance, reset at start of each month | Visa | P2 | Hard | ✓ |
| Q12 | Cumulative users added daily, reset at start of each month | Interview Query | P2 | Hard | |
| Q13 | Running total revenue by product category in 2022 | Generic | P2 | Medium | |
| Q14 | Cumulative salary of employee for 3 months excluding most recent (LeetCode Hard) | LeetCode | P2 | Hard | |
| Q15 | Total server fleet uptime across overlapping maintenance windows | Amazon | P2+P12 | Hard | |
| Q16 | Month-over-month change in revenue for 2019 | Interview Query | P2+P3 | Medium | |
| Q17 | Duplicate payments: same merchant+card+amount within 10 minutes | Stripe | P3 | Hard | ✓ |
| Q18 | Average delay between sign-up and 2nd ride (in-the-moment users) | Uber | P3 | Hard | |
| Q19 | Twitter rolling 3-day average number of tweets per user | P2 | Medium | ✓ | |
| Q20 | % buyers who purchased AirPods directly after iPhone (next purchase) | Apple | P3 | Hard | ✓ |
| Q21 | Countries that moved higher in comment ranking Dec→Jan | P3 | Hard | ||
| Q22 | 3 largest month-over-month call declines by company | RingCentral | P3 | Hard | |
| Q23 | Users whose 2nd purchase was within 48 hours of 1st | Amazon | P3 | Medium | |
| Q24 | Rows where purchase amount grew vs previous transaction | Ankit Bansal | P3 | Medium | |
| Q25 | Top 3 users with longest continuous login streak | StrataScratch | P4 | Hard | ✓ |
| Q26 | Employees who worked consecutive days for at least 5 days straight | Ankit Bansal | P4 | Hard | |
| Q27 | Periods of inactivity for each supplier — longest gap between orders | Ankit Bansal | P4 | Hard | |
| Q28 | Users who placed orders every week for 4+ consecutive weeks | LeetCode variant | P4 | Hard | |
| Q29 | Stocks with consecutive days of price increases (3+ in a row) | Bloomberg variant | P4 | Hard | |
| Q30 | Date ranges when a server was continuously online | Amazon/Google | P4 | Hard | |
| Q31 | Users with no activity for 30+ days at any point in history | PracticeWindowFunctions | P4 | Hard | |
| Q32 | Assign session_id to each event (new session = 30 min inactivity) | Mode Analytics | P5 | Hard | ✓ |
| Q33 | Average session duration per user (session = 30 min gap) | P5 | Hard | ||
| Q34 | Users with highest number of sessions in a given month | P5 | Hard | ||
| Q35 | Sessions that resulted in a purchase within the same session | Amazon | P5 | Hard | |
| Q36 | Users whose first session was as viewer but later became streamer | Twitch | P5 | Medium | |
| Q37 | Count duplicate customer_id entries from ETL bug | Amazon | P6 | Easy | |
| Q38 | From CDC table, keep most recent record per customer_id | Databricks | P6 | Medium | ✓ |
| Q39 | Duplicate transaction_ids — keep record with highest amount | Stripe variant | P6 | Medium | |
| Q40 | Users with more than one account (same email, different user_ids) | P6 | Easy | ||
| Q41 | Deduplicate user_profiles keeping lowest user_id per email | Meta | P6 | Medium | |
| Q42 | Employees who earn more than their direct manager | Amazon/Microsoft | P7 | Medium | ✓ |
| Q43 | Friend recommendations: users who attend 2+ same events, not already friends | P7 | Hard | ||
| Q44 | Pairs of students in same class who scored within 5 points of each other | Academic | P7 | Medium | |
| Q45 | Cheapest two-stop routes between any origin-destination pair | Delta Airlines | P7 | Hard | |
| Q46 | Players who beat same opponent at least twice | Sports/Ankit Bansal | P7 | Medium | |
| Q47 | Managers with at least 5 direct reports | LeetCode | P7 | Easy | |
| Q48 | All possible size-color combinations for new product line | Generic retail | P8 | Easy | |
| Q49 | Full date × product grid, LEFT JOIN sales to find zero-sales days | Amazon/Walmart | P8 | Medium | |
| Q50 | Full round-robin tournament schedule from teams table | Sports / McKinsey | P8 | Medium | |
| Q51 | All 3-topping pizza combinations with total cost | McKinsey | P8 | Medium | ✓ |
| Q52 | Full region × category grid for monthly report (zero-fill) | Retail DE | P8 | Medium | |
| Q53 | Top 5 pairs of products most frequently bought together | Interview Query | P9 | Hard | ✓ |
| Q54 | Product most commonly bought alongside Product X | Amazon/Instacart | P9 | Medium | |
| Q55 | Product pairs where co-purchase count > 100 with lift score | E-commerce | P9 | Hard | |
| Q56 | Menu item pairs ordered together more than 30% of the time | Swiggy/Ankit Bansal | P9 | Hard | |
| Q57 | Downloads for paying vs non-paying users by date (filter where non-paying > paying) | Microsoft | P10 | Medium | ✓ |
| Q58 | Click-through rate: 100 × clicks / impressions per app | P10 | Medium | ✓ | |
| Q59 | Pivot monthly revenue by product category (categories become columns) | Walmart | P10 | Medium | |
| Q60 | Users active on exactly 3 out of past 7 days | Facebook/Google | P10 | Medium | |
| Q61 | Orders placed per quarter (Q1,Q2,Q3,Q4) as separate columns per user | Amazon | P10 | Medium | |
| Q62 | Twitch users who are both streamers and viewers — count sessions per type | Twitch | P10 | Medium | |
| Q63 | Monthly active users in July 2022 (active in BOTH June and July) | P11 | Hard | ✓ | |
| Q64 | Retention rate of monthly sign-up cohort for months 1, 2, and 3 | Interview Query | P11 | Hard | |
| Q65 | Day-7 retention rate for January 2024 sign-ups | Google/Facebook | P11 | Hard | |
| Q66 | Weekly sign-up cohort: % who made 2nd purchase within 30 days | Amazon | P11 | Hard | |
| Q67 | D1, D7, D30 retention side-by-side per monthly sign-up cohort | Meta | P11 | Hard | |
| Q68 | How unsubscribes affect login rates over 4 weeks after event | Interview Query | P11 | Hard | |
| Q69 | Days between first and last post of year per user (at least 2 posts) | P12 | Medium | ✓ | |
| Q70 | Average hours between order placement and delivery (2023) | Amazon | P12 | Easy | |
| Q71 | Employees at company 5+ years but never promoted | HR/Ankit Bansal | P12 | Medium | |
| Q72 | % incomplete orders and revenue lost in past 90 days | Uber | P12 | Medium | |
| Q73 | Subscription renewals more than 7 days late | PayPal/Stripe | P12 | Medium | |
| Q74 | All employees reporting directly/indirectly to manager_id = 5 | Amazon/Microsoft | P13 | Hard | ✓ |
| Q75 | Total subordinate count (direct + indirect) for each manager | P13 | Hard | ||
| Q76 | Product categories and all subcategories recursively | E-commerce | P13 | Hard | |
| Q77 | Full dependency chain for a given task (task depends on task) | Project Mgmt | P13 | Hard | |
| Q78 | Generate date spine 2024-01-01 to 2024-12-31 using recursive CTE | DE Pattern | P13 | Medium | |
| Q79 | All reachable destinations from an origin city (multi-hop flights) | Delta Airlines | P13 | Hard | |
| Q80 | Median number of searches per user from frequency distribution table | P14 | Hard | ✓ | |
| Q81 | Median salary of employees in each department | LeetCode Hard | P14 | Hard | |
| Q82 | 90th percentile response time per API endpoint in past week | Engineering | P14 | Medium | |
| Q83 | Divide users into 4 quartiles by total purchase amount 2023 | Retail/Amazon | P14 | Medium | ✓ |
| Q84 | Median days between 1st and 2nd purchase for customers with 2+ purchases | E-commerce | P14 | Hard | |
| Q85 | Count of users at each funnel stage + step-to-step conversion rate | TikTok/Stripe | P15 | Hard | ✓ |
| Q86 | Signup-to-activation rate (confirmed phone / total signed up) | TikTok | P15 | Medium | ✓ |
| Q87 | Drop-off rate at each step of onboarding funnel | DoorDash/Instacart | P15 | Hard | |
| Q88 | Click-through-to-conversion rate per ad campaign | Google Ads | P15 | Hard | |
| Q89 | Funnel step with highest drop-off for new users in first 7 days | Facebook/Uber | P15 | Hard | |
| Q90 | Free trial → paid conversion rate changes across monthly cohorts | SaaS/Stripe | P15 | Hard |
HOW TO ADD YOUR OWN QUESTIONS
When you receive a new SQL interview question, add it here:
| Q91 | [Your question text] | [Company if known] | P? | Medium/Hard | |
Then tell me the question and I will:
- Identify the correct pattern (P1–P15)
- Add the solved solution to the appropriate pattern file
- Update this bank with the correct pattern number
QUESTIONS TO CLASSIFY (Add yours here when you remember them)
| # | Question | Company | Status |
|---|---|---|---|
| - | (your interview questions go here) | - | Pending |