🗃️
SQL
SQL Question Bank — Master Tracking File
🗃️
🗃️
SQL · Section 9 of 9

SQL Question Bank — Master Tracking File

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 NameKey SQL
P1Ranking / Top-N Per GroupROW_NUMBER, RANK, DENSE_RANK + PARTITION BY
P2Running Totals / CumulativeSUM() OVER (ORDER BY)
P3LAG / LEAD — Row-over-RowLAG(), LEAD()
P4Gaps & Islandsdate - ROW_NUMBER() island grouping
P5SessionizationLAG() gap detection + cumulative SUM as session_id
P6DeduplicationROW_NUMBER() PARTITION BY, keep rank = 1
P7Self-JoinSame table aliased twice
P8Cross Join — CombinationsCROSS JOIN for Cartesian product
P9Market Basket / Co-occurrenceSelf-join on order_id, item1 < item2
P10Conditional Aggregation / PivotSUM(CASE WHEN ...)
P11Cohort / Retention AnalysisMIN(event_date) as cohort + date offset
P12Date ArithmeticDATEDIFF, DATE_TRUNC, INTERVAL
P13Recursive CTEWITH RECURSIVE anchor + recursive step
P14Median / PercentilePERCENTILE_CONT or ROW_NUMBER median trick
P15Funnel AnalysisMulti-stage COUNT DISTINCT + conversion rate

FULL QUESTION BANK

Q#QuestionCompanyPatternDifficultySolved?
Q01Top 2 highest-grossing products within each category in 2022AmazonP1Medium
Q02Top 3 salaries in each departmentFAANG ClassicP1Medium
Q03Email activity rank per user (sent + received + spam, dense ranked)GoogleP1Medium
Q04Top 2 users per company with most calls (maintain ties)RingCentralP1Medium
Q05Most-used vehicle type in past year (excluding cancelled rides)UberP1Easy-Med
Q06Olympic swimmers who won ONLY gold medals — count golds eachAmazonP1Medium
Q07Nominee who won the most OscarsNetflixP1Easy
Q08Top 10 users by total distance across all ridesLyftP1Medium
Q09Top 5 product pairs most frequently purchased togetherInterview QueryP1+P9Hard
Q10Top 3 departments by average salaryClassicP1Easy
Q11Cumulative merchant transaction balance, reset at start of each monthVisaP2Hard
Q12Cumulative users added daily, reset at start of each monthInterview QueryP2Hard
Q13Running total revenue by product category in 2022GenericP2Medium
Q14Cumulative salary of employee for 3 months excluding most recent (LeetCode Hard)LeetCodeP2Hard
Q15Total server fleet uptime across overlapping maintenance windowsAmazonP2+P12Hard
Q16Month-over-month change in revenue for 2019Interview QueryP2+P3Medium
Q17Duplicate payments: same merchant+card+amount within 10 minutesStripeP3Hard
Q18Average delay between sign-up and 2nd ride (in-the-moment users)UberP3Hard
Q19Twitter rolling 3-day average number of tweets per userTwitterP2Medium
Q20% buyers who purchased AirPods directly after iPhone (next purchase)AppleP3Hard
Q21Countries that moved higher in comment ranking Dec→JanFacebookP3Hard
Q223 largest month-over-month call declines by companyRingCentralP3Hard
Q23Users whose 2nd purchase was within 48 hours of 1stAmazonP3Medium
Q24Rows where purchase amount grew vs previous transactionAnkit BansalP3Medium
Q25Top 3 users with longest continuous login streakStrataScratchP4Hard
Q26Employees who worked consecutive days for at least 5 days straightAnkit BansalP4Hard
Q27Periods of inactivity for each supplier — longest gap between ordersAnkit BansalP4Hard
Q28Users who placed orders every week for 4+ consecutive weeksLeetCode variantP4Hard
Q29Stocks with consecutive days of price increases (3+ in a row)Bloomberg variantP4Hard
Q30Date ranges when a server was continuously onlineAmazon/GoogleP4Hard
Q31Users with no activity for 30+ days at any point in historyPracticeWindowFunctionsP4Hard
Q32Assign session_id to each event (new session = 30 min inactivity)Mode AnalyticsP5Hard
Q33Average session duration per user (session = 30 min gap)GoogleP5Hard
Q34Users with highest number of sessions in a given monthFacebookP5Hard
Q35Sessions that resulted in a purchase within the same sessionAmazonP5Hard
Q36Users whose first session was as viewer but later became streamerTwitchP5Medium
Q37Count duplicate customer_id entries from ETL bugAmazonP6Easy
Q38From CDC table, keep most recent record per customer_idDatabricksP6Medium
Q39Duplicate transaction_ids — keep record with highest amountStripe variantP6Medium
Q40Users with more than one account (same email, different user_ids)FacebookP6Easy
Q41Deduplicate user_profiles keeping lowest user_id per emailMetaP6Medium
Q42Employees who earn more than their direct managerAmazon/MicrosoftP7Medium
Q43Friend recommendations: users who attend 2+ same events, not already friendsFacebookP7Hard
Q44Pairs of students in same class who scored within 5 points of each otherAcademicP7Medium
Q45Cheapest two-stop routes between any origin-destination pairDelta AirlinesP7Hard
Q46Players who beat same opponent at least twiceSports/Ankit BansalP7Medium
Q47Managers with at least 5 direct reportsLeetCodeP7Easy
Q48All possible size-color combinations for new product lineGeneric retailP8Easy
Q49Full date × product grid, LEFT JOIN sales to find zero-sales daysAmazon/WalmartP8Medium
Q50Full round-robin tournament schedule from teams tableSports / McKinseyP8Medium
Q51All 3-topping pizza combinations with total costMcKinseyP8Medium
Q52Full region × category grid for monthly report (zero-fill)Retail DEP8Medium
Q53Top 5 pairs of products most frequently bought togetherInterview QueryP9Hard
Q54Product most commonly bought alongside Product XAmazon/InstacartP9Medium
Q55Product pairs where co-purchase count > 100 with lift scoreE-commerceP9Hard
Q56Menu item pairs ordered together more than 30% of the timeSwiggy/Ankit BansalP9Hard
Q57Downloads for paying vs non-paying users by date (filter where non-paying > paying)MicrosoftP10Medium
Q58Click-through rate: 100 × clicks / impressions per appFacebookP10Medium
Q59Pivot monthly revenue by product category (categories become columns)WalmartP10Medium
Q60Users active on exactly 3 out of past 7 daysFacebook/GoogleP10Medium
Q61Orders placed per quarter (Q1,Q2,Q3,Q4) as separate columns per userAmazonP10Medium
Q62Twitch users who are both streamers and viewers — count sessions per typeTwitchP10Medium
Q63Monthly active users in July 2022 (active in BOTH June and July)FacebookP11Hard
Q64Retention rate of monthly sign-up cohort for months 1, 2, and 3Interview QueryP11Hard
Q65Day-7 retention rate for January 2024 sign-upsGoogle/FacebookP11Hard
Q66Weekly sign-up cohort: % who made 2nd purchase within 30 daysAmazonP11Hard
Q67D1, D7, D30 retention side-by-side per monthly sign-up cohortMetaP11Hard
Q68How unsubscribes affect login rates over 4 weeks after eventInterview QueryP11Hard
Q69Days between first and last post of year per user (at least 2 posts)FacebookP12Medium
Q70Average hours between order placement and delivery (2023)AmazonP12Easy
Q71Employees at company 5+ years but never promotedHR/Ankit BansalP12Medium
Q72% incomplete orders and revenue lost in past 90 daysUberP12Medium
Q73Subscription renewals more than 7 days latePayPal/StripeP12Medium
Q74All employees reporting directly/indirectly to manager_id = 5Amazon/MicrosoftP13Hard
Q75Total subordinate count (direct + indirect) for each managerGoogleP13Hard
Q76Product categories and all subcategories recursivelyE-commerceP13Hard
Q77Full dependency chain for a given task (task depends on task)Project MgmtP13Hard
Q78Generate date spine 2024-01-01 to 2024-12-31 using recursive CTEDE PatternP13Medium
Q79All reachable destinations from an origin city (multi-hop flights)Delta AirlinesP13Hard
Q80Median number of searches per user from frequency distribution tableGoogleP14Hard
Q81Median salary of employees in each departmentLeetCode HardP14Hard
Q8290th percentile response time per API endpoint in past weekEngineeringP14Medium
Q83Divide users into 4 quartiles by total purchase amount 2023Retail/AmazonP14Medium
Q84Median days between 1st and 2nd purchase for customers with 2+ purchasesE-commerceP14Hard
Q85Count of users at each funnel stage + step-to-step conversion rateTikTok/StripeP15Hard
Q86Signup-to-activation rate (confirmed phone / total signed up)TikTokP15Medium
Q87Drop-off rate at each step of onboarding funnelDoorDash/InstacartP15Hard
Q88Click-through-to-conversion rate per ad campaignGoogle AdsP15Hard
Q89Funnel step with highest drop-off for new users in first 7 daysFacebook/UberP15Hard
Q90Free trial → paid conversion rate changes across monthly cohortsSaaS/StripeP15Hard

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:

  1. Identify the correct pattern (P1–P15)
  2. Add the solved solution to the appropriate pattern file
  3. Update this bank with the correct pattern number

QUESTIONS TO CLASSIFY (Add yours here when you remember them)

#QuestionCompanyStatus
-(your interview questions go here)-Pending