By role
SQL interview questions for business and BI analysts
Business and BI analyst screens are about the numbers a business runs on: revenue, margins and shares, month over month and year over year, and reports where every category has to show up even when it is zero.
What to get right
- Cast before you divide. Integer division turns 2/3 into 0.
- Define the period exactly: calendar month, last 30 days, or month to date.
- Pivot with SUM(CASE WHEN ...) or FILTER, and know both.
Group and aggregate Read the lesson
- Billed, paid and outstanding by industryFinance wants a receivables summary by customer industry, using every invoice in invoices.
- First and last product name and launch date by categoryThe catalog team is tidying the product list and wants a quick profile of each category.
- First response times by priorityThe support lead wants a response-time summary for each ticket priority, using every row in tickets.
- Five-star trips per driver in June, idle drivers includedThe community team wants to thank drivers for great service and also see who got no recognition. For June 2025, count each driver's five-star trips.
- Monthly money in, money out and net flowFinance wants a monthly cash-flow table for the whole bank, using every row in transactions.
- Orders, coupon orders and customers by channelThe marketing lead wants one summary line per sales channel. Use every row in orders, whatever its status.
- Revenue by category, including empty onesFinance wants revenue for every product category in the catalog. Revenue is quantity * unit_price from order_items, counting completed orders only.
- Accounts with a high average invoiceThe revenue team wants a shortlist of big-ticket accounts. Use every invoice in invoices, paid or not.
- Artist catalog size and 2025 releasesThe label relations team wants a status line for every artist: how big the catalog is, and how much of it is new this year.
- Average order value by channelThe growth team tracks average order value (AOV) for each sales channel. Only completed orders count.
- Average rating per city, weighted by tripsThe quality team publishes one rider rating per city. A rider may skip the rating, so rider_rating is NULL on many completed trips.
- Busy accounts in May and the fees they paidThe pricing team is reviewing fees on very active accounts. Look at transactions with posted_at on or after 2025-05-01 00:00:00 and before 2025-06-01 00:00:00.
- Categories behind each agent's unhappy surveysThe support manager is preparing one-to-one meetings. For each agent she wants to see which ticket categories ended in an unhappy customer.
- Completed trips by driver tenure bandThe driver success team wants to know whether newer drivers earn less per trip. Use completed trips only.
- Customers grouped by how many orders they placedThe CRM team wants to split 2025 shoppers into three groups by how often they bought.
- Customers whose every account is closedThe retention team wants a list of customers who have left the bank entirely.
- Fare per kilometre by city and vehicle typeThe pricing team compares how much a kilometre earns in each city for each kind of vehicle. Use completed trips only.
- Resolution speed buckets and satisfactionThe support lead wants to know whether slow resolutions make customers unhappy.
- Overdue invoices by account managerCollections wants an overdue list by account owner. Today is 2025-06-30 for this report.
- Plan stretches and billing for accounts that changed planCustomer success is reviewing accounts that moved between plans.
- Spend mix by customer segmentThe product team wants to see how each customer segment splits its everyday spending.
Conditional aggregation Read the lesson
- Average fare for short and long tripsPricing wants to compare what short and long trips earn in each city. Only completed trips count (status = 'completed'). A short trip has distance_km under 5.
- Order status counts per channelThe operations lead wants one row per sales channel showing how its orders ended up.
- Products per price band, empty bands includedMerchandising groups the catalog into four price bands by list_price in products.
- Rider cancellations per completed trip, by cityCity managers want to know how many riders cancel for every trip that actually happens.
- Active subscriptions by seat band and planSales ops wants a grid of live subscriptions on 30 June 2025: seat bands down the side, plans across the top.
- Customers who buy in the app but never on the webThe growth team wants a list of customers who shopped only in the app during the second quarter of 2025, so they can test a web-checkout nudge on them.
- Money in and money out per savings accountRisk wants a February 2025 cash-flow summary for every savings account. In transactions, a positive amount is money in and a negative amount is money out.
- On-time, late and unpaid invoices by monthCollections wants to see how each month's invoices were settled.
- First-response SLA by agentThe support lead scores agents on first-response speed.
- Seven-day buyer rate by campaignMarketing judges each campaign by how many of its sign-ups buy within a week.
Period over period Read the lesson
- Quarter-over-quarter invoiced revenueThe CFO reviews invoicing one quarter at a time. Calendar quarters start on 1 January, 1 April, 1 July and 1 October.
- Biggest month-over-month spending drop per categoryThe cards team wants to know in which month customers cut back the most in each everyday spending category.
- Channel share of ad spend, Q1 against Q2Marketing wants to see how the mix of ad spend moved between the first two quarters of 2025.
- Month-over-month change in invoicingFinance tracks the month-over-month change in invoiced amount.
- Week-over-week high-priority ticketsThe support lead watches how many serious tickets arrive each week. A serious ticket has priority of high or urgent.
- Year-over-year completed orders by monthFinance compares each month of 2025 with the same month of 2024. Count orders with status completed, assigned to the calendar month of ordered_at.
- New and churned seats by monthFinance splits each month's movement in customers into new and churned. Take a snapshot of every account on the first day of each month.
- Year-to-date units against the same period last yearMerchandising tracks year-to-date unit sales and asks whether 2025 is ahead of 2024 at the same point in the year.
Ratios and percentages Read the lesson
- Cancellation rate by cityCity managers want to know how often a ride request ends in a cancellation.
- Cost per click, with zero-click campaignsFinance wants the cost per click (CPC) of every campaign: all the money it spent divided by all the clicks it got, in US dollars.
- Share of revenue by categoryThe merchandising team wants to see how completed sales split across product categories.
- Click-through rate by campaignThe marketing team reports the click-through rate (CTR) of each campaign: all the clicks it received divided by all the impressions it served, over every...
- Driver cancellations among accepted ridesDriver operations wants to know how often a driver backs out after accepting a request.
- On-time payment rate by industryFinance wants to know which industries pay on time. An invoice was paid on time when paid_on is on or before due_on.
- Refund rate by count and by valueFinance tracks refunds in two ways: how many orders were refunded, and how much money they were worth.
- Sign-up to purchase conversion by campaignThe growth team judges each campaign by how many of its sign-ups ever bought something.
- Survey response rate and CSAT by teamThe support lead tracks two numbers for every team, and they have different denominators.
- Return rate by product categoryOperations wants to know which categories come back the most. For each category, the return rate is the units returned divided by the units sold.
- Revenue per account, including non-payersLeadership wants the average collected revenue per account for each industry.
- Spending share by category within each segmentThe bank wants to see how each customer segment spends its money.
Dates and time Read the lesson
- Average pickup wait and trip length in minutesOperations tracks how long riders wait and how long trips take.
- May trip requests by city, last day includedCity managers want the May 2025 request count for every city. Count the trips requested from 2025-05-01 00:00:00 through the end of 2025-05-31.
- Monthly cost per click by channelThe marketing team compares how much a click costs on each channel, month by month, for January to June 2025.
- Weekly ticket volume, weeks starting MondayThe support lead reports ticket volume per week for March 2025. Count the tickets created from 2025-03-01 00:00:00 up to and including the whole of 2025-03-31.
- First response within one hour, by channelThe support desk promises a first reply within one hour.
- Overdue invoices as of a fixed dateCollections reviews the books as they stood at the end of 2025-05-31.
- Subscriptions active on a given dateFinance asks for a snapshot of paying seats on 2025-03-15. A subscription is active on a date when it started on or before that date and has not ended by then.
- Weekend vs weekday revenue per calendar dayThe shopping app team wants to know whether weekends earn more than weekdays in May 2025.
- Live campaign days with no deliveryAd ops suspects some campaigns stopped serving on days they were supposed to be live.
- Month-end balance by account typeFinance reports the combined balance of each account type at the end of every month, from January to June 2025.
- Seats on the last day of each monthFinance reports month-end paying seats.
Joins Read the lesson
- April spend and cost per click for search and socialThe paid team reviews campaigns on the search and social channels for April 2025 (from 2025-04-01 to 2025-04-30 inclusive, by ad_daily.day).
- Email-referred customers and their completed ordersThe lifecycle team wants to see how well the email channel converts. Look at every customer whose referral_source is 'email'.
- Headcount by department, empty and unassigned includedThe people team needs a headcount table that accounts for every department and every person. Count current employees only: those whose termination_date is NULL.
- Recurring revenue by plan on a given dayFinance asks what the subscription book looked like on 15 March 2025.
- Urgent email and phone tickets by team, with unassignedThe support lead reviews urgent tickets that came in by email or phone (priority = 'urgent' and channel is 'email' or 'phone') and how happy customers were.
- Completed trips for every city and vehicle typeOperations is building a grid for a dashboard: one row for every combination of a city and a vehicle type, so that empty cells are visible.
- Invoiced amount by the plan active on the issue dateInvoices do not store a plan. To attribute revenue to plans, link each invoice to the subscription its account had on the invoice's issued_on day.
- Kitchen revenue by customer country, four tablesThe merchandising team wants to know where the Kitchen range sells. A customer's country is customers.country.
- Organic sign-ups during each campaign's runThe growth team wants a rough sense of the background sign-up rate while each campaign ran. A campaign was live from started_on to ended_on, both days included.
- Tickets per response band from a band lookup tableThe support team reports how fast it answers. The response time of a ticket is the time from created_at to first_response_at, in minutes (fractions allowed).
- Daily spend against sign-ups for one campaignThe growth team is reconciling two sources for the "Family meals video" campaign (campaign_id = 3) in May 2025: the ad platform's daily spend (ad_daily)...
- Open accounts at each month end, by account typeFinance reports the number of open accounts on the last day of every month, split by account type.
- Salary in effect at review time, by ratingThe people team asks whether higher ratings go with higher pay.
More for this role
- Five longest-serving employees, keeping ties at the cut-offRanking and top N
- Products at the three highest price pointsRanking and top N
- Three slowest first responses in each channelRanking and top N
- Top earner in each department, with a tie-breakerRanking and top N
- Average first purchase value by campaign, organic includedRanking and top N
- Best seller on each sales channel in the first quarterRanking and top N
- Employees in the top quarter of pay, by PERCENT_RANKRanking and top N
- First order value by acquisition channelRanking and top N
- Months each merchant ranked in the top three for spendRanking and top N
- Top three drivers in each city, ties at third place keptRanking and top N
- Top three products in each category, with tiesRanking and top N
- Top two agents per team by satisfaction, with tie-breakersRanking and top N
- Two cheapest campaigns per month by cost per clickRanking and top N
- Favourite spending category per customer, counted by segmentRanking and top N
- Repeat contact within 14 days of a first ticketRanking and top N
- Cumulative revenue by day, including quiet daysRunning totals, LAG and LEAD
- Invoices where the amount changedRunning totals, LAG and LEAD
- Percentage change from the previous salaryRunning totals, LAG and LEAD
- Running balance for one bank accountRunning totals, LAG and LEAD
- Running earnings for two driversRunning totals, LAG and LEAD
- Dining spend that restarts each monthRunning totals, LAG and LEAD
- Hours since the customer's previous ticketRunning totals, LAG and LEAD
- The invoice that takes an account past 5,000 billedRunning totals, LAG and LEAD
- Products that make up 80 percent of revenueRunning totals, LAG and LEAD
- Agent share of their team's ticketsCTEs and subqueries
- Employees paid above their department averageCTEs and subqueries
- Months billed above the monthly averageCTEs and subqueries
- Average transactions per open accountCTEs and subqueries
- Customers whose first order used a couponCTEs and subqueries
- Orders above the customer's own average orderCTEs and subqueries
- Ticket categories with an above-average urgent shareCTEs and subqueries
- Campaigns cheaper per sign-up than their channelCTEs and subqueries
- Customers by referral source, with unknown shownNULL handling
- Invoices issued, paid and unpaid by industryNULL handling
- Orders that did not use a couponNULL handling
- Total fare by city, including cities with no completed tripsNULL handling
- Average fare per request and per completed tripNULL handling
- Average satisfaction score by channelNULL handling
- Number campaigns by end date, running ones lastNULL handling
- Tickets by first response time bandNULL handling
- Tickets per agent, including unassigned onesNULL handling
- Colleagues hired in the same month and departmentSelf joins
- Repeat tickets from the same customer within a weekSelf joins
- Skip-level managers and how many people they coverSelf joins
- Employees paid more than their managerSelf joins
- Products bought together in the same orderSelf joins
- How many drivers in the same city rate higherSelf joins
- Agents who got no urgent ticket in AprilRows with no match
- Campaigns that never brought in a paying userRows with no match
- Customers with no completed order in MarchRows with no match
- Products that sold but were never returnedRows with no match
- Accounts billed since May with no paid invoiceRows with no match
- Customers with savings but no open checking accountRows with no match
- Sign-ups who never bought, by sign-up monthRows with no match
- Repeat tickets from the same customerDeduplication and latest row
- Salary in effect on a date for each employeeDeduplication and latest row
- Revenue to date per customer by sign-up quarterCohorts and retention
- Rolling retention after day 30 by first-order quarterCohorts and retention
- Week-two retention by acquisition channelCohorts and retention
- Weekly sign-up cohorts and next-week buyersCohorts and retention
- Month-over-month net revenue retentionCohorts and retention
- Monthly subscription churn rateCohorts and retention
- Customer activation funnel by segmentFunnels
- Ad funnel from impressions to buyers by channelFunnels
- Biggest drop-off step in the ride funnelFunnels
- Longest run of delivery days per campaignGaps and islands
- Median salary by departmentMedians and percentiles
- Customers by email domainText and set operations
- Customers who bought from two categoriesText and set operations
- Current gold customers by region from type 2 historyAnalytics engineering
- Active accounts and seats per day from subscription datesAnalytics engineering
- Agent by month fact table of tickets created and resolvedAnalytics engineering
- Monthly recurring revenue by plan with empty monthsAnalytics engineering
- Reconcile active subscriptions against February invoicesAnalytics engineering
- Campaign by day fact table with cumulative spendAnalytics engineering