SQL Conditional Logic Practice Problems: 265 Questions with Solutions
265 SQL conditional logic practice problems with solutions: CASE WHEN, IF, COALESCE and conditional aggregation. Written in MySQL, judged on hidden datasets.
- Problems: 265
- By difficulty: 76 easy · 127 medium · 62 hard
- Dialect: MySQL
Practise conditional logic in SQL: CASE WHEN, IF, COALESCE and IFNULL, and conditional aggregation such as SUM(CASE WHEN … THEN 1 ELSE 0 END) to pivot rows into columns. These problems label rows into buckets, count several conditions in one pass and replace missing values — the pattern behind most "report" questions in a SQL interview.
Easy SQL conditional logic problems
- Is the Playing XI Combination Valid?
- Rating Report for Each Canteen Counter
- Loan Applicants by Credit Score Band
- Polling Booth Turnout Bands
- Cash Donations and 80G Eligibility
- Prepaid High-Value Orders Awaiting Dispatch
- Cart Shipping Fee and Amount Payable
- Fee Invoices Paid Late or Still Overdue
- Exam Marks to University Grade Letters
- Faculty Names Formatted for ID Cards
- Payable Amount on Surge-Priced Orders
- Refund Due on Cancelled Food Orders
- Gamertags Breaking the Naming Policy
- Battle Pass Progress Labels for Season 12
- Label Each Insurance Claim by How It Settled
- Doctor Names for the Prescription Letterhead
- On-Payroll Headcount by Department and Work Mode
- Work E-mail Addresses for New Joiners
- Dimensional Inspection: Pass, Rework or Scrap
- Click-Through Rate of Every Ad Group
- Email Campaigns That Drove Two or More Unsubscribes
- Label Each Campaign by Its Monthly Budget Tier
- Ride Request Outcome Mix: Rider, Driver or No Driver
- Deployment Outcomes per Service
- Label CSAT Survey Responses by Sentiment
- Maintenance Tickets Breaching the Seven-Day SLA
- Broker Commission by Deal Slab
- Net Stock Change per SKU From the Movement Log
- Workspace Seat Utilisation Status
- Label Accounts Active, Dormant or Churned
- Full-Time Results Board for the Football League
- Batters Who Were Out for a Duck This Season
- Accounts With Two or More Kids Profiles
- Short, Standard and Long Episodes
- Cell Tower Dropped-Call Health Check
- Flight Bookings by Sales Channel
- Current Status Labels for Train PNRs
- Loyalty Tier Headcount From Points Balance
- Airbnb: Average Cleaning Fee by Property Type
- Airbnb: Friday and Saturday Check-Ins per City
- Airbnb: Host Payout for Each Completed Stay
- Airbnb: Host Display Names With a Last Initial
- Amazon: Return Requests With No Delivered Order Behind Them
- Amazon: Subscribe & Save Discount Tier per Delivery Month
- Amazon: EC2 Billable Seconds With the One-Minute Minimum
- Apple: iCloud Accounts Using More Than Their Plan
- Apple: Online Orders With Both an iPhone and AirPods
- Dream11: Gross Winnings, Tax Withheld and Net Payout per User
- Flipkart: Plus Members Sitting on Unused SuperCoins
- Flipkart: COD Orders Shipped to Pincodes Without COD
- Flipkart: Instant Discount From Each Bank Offer
- Google: Zero-Result Searches per Locale
- Google: Pixel Units Sold and Returned per Model
- Google: Read Match Type From Ad Keyword Syntax
- LinkedIn: InMail Response Rate per Recruiter
- LinkedIn: Easy Apply Share of Applications per Job
- Meta: Going and Interested Counts per Facebook Event
- Microsoft: Outlook Mailboxes at 90% of Their Quota or More
- Microsoft: Azure Subscription Budget Status This Month
- Myntra: Insider Points Earned on Each Delivered Order
- Myntra: M-Now Deliveries Inside the 30-Minute Promise by Store
- Ola: Scooters Still Below MoveOS 4.2
- Ola: Test Ride Bookings and No-Shows per Experience Centre
- Ola: Scooters Due for Their First Free Service
- Paytm: Wallet Users by KYC Level in Each City
- Paytm: Digital Gold Customers Holding at Least One Gram
- PhonePe: Labelling Scratch Card Rewards for the Rewards Page
- Razorpay: Captured Volume by Payment Method per Merchant
- Razorpay: Magic Checkout Conversion Rate by Merchant
- Spotify: Skips and Full Plays per Track
- Spotify: Family and Duo Plans With Open Seats
- Swiggy: Genie Fare by Distance Slab
- Walmart: Grocery vs General Merchandise Sales per Store
- Zomato: Veg, Non-Veg and Egg Dishes on Every Menu
- Zomato: Blinkit Store Items Below Their Reorder Level
- Zomato: Hyperpure Invoices Paid Late or Still Overdue
Medium SQL conditional logic problems
- Count Deliveries in Every Time Band
- Customers With a Return: Delivered vs Returned Value
- OTP Verification Rate of Every Account
- Monthly Ticket Refund Report by Railway Zone
- Swap Neighbouring Seats in the Exam Hall
- UPI Payments by Month and City
- UPI Success Rate by App and Month
- Current Balance From the Account Ledger
- Loan Book Asset Classification by Branch
- Grievances Resolved Within the Seven-Day SLA
- Concert Sell-Through and Sales Status
- Monthly Library Issues by Genre
- Grievance Tickets per Ward From Reference Codes
- Cart Abandonment Rate by Device
- Flash Sale Units Sold Inside the Sale Window
- GST Split Into CGST, SGST and IGST by Seller
- Monthly Fee Collection by Payment Mode
- Courses Where More Than a Quarter of Students Failed
- Backlogs Cleared on a Later Attempt
- Riders Missing the Delivery SLA in June 2024
- Peak-Hour Share of Orders by City
- Coupon Discount Spend by Campaign Prefix
- Player Win Rates With at Least Five Matches
- Ranked Queue Wait Time by Hour of Day
- OPD No-Show Rate by Doctor
- Cashless Claims Settled per Insurer per Month
- Medicines Below Their Reorder Level
- Appraisal Rating Mix by Department
- Hiring Funnel for Each Open Requisition
- Performance Bonus Payout for FY2024-25
- Sensor Threshold Breach Rate
- Late Work Order Rate by Line
- EV Charging Peak and Off-Peak Revenue
- Email Open Rate by Hour of Send
- Email Subscribers Who Open but Never Click
- Dispatch Offer Acceptance Rate per Driver
- Monthly Completed Trips, GMV and Average Fare
- First-Response SLA Breach Rate by Priority
- Monthly Change Failure Rate of Production Deploys
- Services Missing Their Uptime Target
- Broker Site-Visit Conversion Rate
- Monthly Rent Collection: On Time, Late and Unpaid
- Co-Living Bed Occupancy by Property
- Store Stock-Out Rate From Daily Closing Stock
- Cycle Count Shrinkage Value by Store and Month
- Warehouse Transfers Still in Transit
- Pricing Page A/B Test Conversion by Variant
- Signups and Upgrades by UTM Source
- Monthly Active Users, New Versus Returning
- Upgrades, Downgrades and Lateral Plan Moves
- Seat-Based Monthly Bill for Every Workspace
- Moderation Outcomes by Report Reason
- Sign-Ups by Email Provider
- Death-Overs Economy From Ball-by-Ball Data
- Share of Seats Booked Two Weeks Early for Each Match
- Goalkeepers' Clean-Sheet Percentage
- Completion Rate of Every Series
- Artist Royalties for May 2024
- Classify Every Plan Change as Upgrade or Downgrade
- Slab Tariff Energy Charges
- Monthly Recharge Revenue by Pack Type
- International Voice Call Share per Caller
- On-Time Arrival Performance by Airline
- Hotel Cancellation Refunds Under a Tiered Policy
- Loyalty Points Expiring for Inactive Members
- Airbnb: Hosts Meeting a Simplified Superhost Bar
- Airbnb: Host Response Rate Within 24 Hours
- Airbnb: Search-to-Booking Funnel by Platform
- Airbnb: Guest Cancellation Rate by Cancellation Policy
- Amazon: Star Rating Breakdown for Each Product
- Amazon: Savings Plan Coverage of Each AWS Account
- Amazon: Referral and FBA Fees per Seller for October
- Apple: Developer Proceeds After Commission in March 2025
- Apple: AppleCare Serial Numbers That Fail the Format Check
- Dream11: Contest Entries by Format for Each Match
- Flipkart: Refund SLA Breaches by Product Category
- Flipkart: Months Members Burned More SuperCoins Than Earned
- Flipkart: Pincodes Where COD Parcels Keep Coming Back
- Flipkart: Products Rated Lower After Big Billion Days
- Flipkart: Certified Buyer Reviews and Their Rating per Product
- Google: Gmail Spam Filter Precision and Recall per Model
- Hotstar: Commentary Language Split per Match
- Hotstar: Unsold Ad Slots by Innings Phase
- LinkedIn: Invitation Acceptance With and Without a Note
- LinkedIn: Members Whose Profile Views Doubled in May
- LinkedIn: Premium Free-Trial Conversion by Trial Month
- Meta: WhatsApp Business Message Delivery Funnel
- Meta: Messenger Call Drops by Major App Version
- Microsoft: Azure Q1 Cost Split by Service Family per Month
- Microsoft: Teams Channels Where Guests Post Most Messages
- Myntra: Size-Related Return Rate by Article Type and Size
- Myntra: Size Exchanges Blocked by an Unavailable Size, per Brand
- Myntra: Styles Most Shoppers Say Run Small
- Ola: Scooters With Outlier Energy Use Within Their Model
- Ola: Rentals Bill With Extra Kilometres and Minutes
- Ola: Wallet Cashback That Was Not Fully Credited
- Ola: OTA Update Adoption in Its First Week, by City
- Ola: Auto, Mini and Prime Ride Mix in Each City
- Paytm: Scratch Cards That Expired Unscratched
- Paytm: Flight Cancellation Refunds Under the Free Window
- PhonePe: Monthly P2P Versus P2M Payment Value in 2024
- PhonePe: Open Share.Market Positions From the Order Book
- PhonePe: Collect-Request Senders Declined More Often Than Not
- PhonePe: Users Who Only Send, Only Receive or Do Both in October
- PhonePe: Rewards Campaign Redemption Report on 1 April
- Razorpay: Card Payment Success Rate by Issuing Bank
- Razorpay: Webhook Events That Never Got a 2xx Response
- Razorpay: Subscription Cycles Recovered by Retry vs Halted
- Razorpay: Expense Claims Not Approved by the Claimant's Manager
- Razorpay: Settlements That Don't Match Their Line Items
- Razorpay: MDR Pricing Rows Added, Removed or Changed Between Snapshots
- Spotify: Ad Load by Market Against the Four-an-Hour Cap
- Spotify: Songwriter Splits That Don't Add Up to 100%
- Swiggy: Share of Each Partner's Orders Delivered in a Batch
- Swiggy: Food Customers Who Later Tried Instamart
- Swiggy: Partner Top-Up to the Shift Earnings Guarantee
- Uber: Surge Share of Bengaluru Trips by Hour of Day
- Uber: Pickup ETA Accuracy by City
- Uber: Drivers Gone Quiet Before the Festive Rush
- Uber: UberX Share Requests Matched With a Co-Rider
- Uber: Back-to-Back Trips Starting in the Last Drop Zone
- Walmart: Price Match Approval Rate by Competitor
- Walmart: Substitutions Made Against the Customer's Wishes
- Walmart: Late Store Deliveries by Day of the Week
- Zomato: Gold Membership Renewal Rate by Plan
- Zomato: Table Reservation No-Show Rate by Meal Slot
- Zomato: September Photo Decisions of Every Moderator
Hard SQL conditional logic problems
- Daily Cancellation Rate Without Suspended Members
- First Day a Member's Fine Balance Reached ₹500
- Overlapping Flash Sales on the Same Product
- Course Funnel From Enrolment to Certificate
- Food App Checkout Funnel, Step by Step
- Rider Cash-in-Hand Between Deposits
- New-Player Funnel From Install to First Purchase by Platform
- Patients With Three or More No-Shows in a Row
- Insurance Claim Funnel by Insurer
- 90- and 180-Day Retention of 2024 Hires by Quarter
- Leave Ledger Entries That Took the Balance Negative
- Sustained Vibration Breach Episodes
- Service-Due Day in Each Maintenance Cycle
- Click to Sign-up to Purchase Funnel per Campaign
- Creators Booked by Two Rival Brands at Once
- Rider App Sessions and Booking Conversion
- Parcel Delivery Funnel and First-Attempt Rate by City
- Sessionise API Calls and Count Server Errors
- Tenants Late on Rent Three Months Running
- Enquiry-to-Token Funnel by Lead Source
- Supplier On-Time-In-Full Rate by Order Quarter
- Onboarding Funnel With Steps Taken in Order
- MRR Movements: New, Expansion, Contraction and Churn
- First-Week Retention by Sign-Up Month
- App Sessions From the Event Stream
- Net Run Rate of Every Team in the T20 League
- Free-Trial Conversion and Second-Month Funnel
- Daily Network Drop Rate Including Silent Days
- Electricity Bill Settlement From Part Payments
- App Sessions That End in a Hotel Booking
- Airbnb: Reconcile Host Payouts Against Earnings
- Airbnb: Quote Stays From Nightly Prices and Discounts
- Amazon: Clearing Price of Each Sponsored Products Auction
- Amazon: AWS Promotional Credits Applied Month by Month
- Dream11: Contest Winners From Player Points With C and VC Boosts
- Flipkart: Big Billion Days GMV by Sale Day Against Last Year
- Flipkart: Month-to-Month Sales Quartile Movement Matrix
- Google: Search Experiment Lift Without Contaminated Users
- Hotstar: Commentary Feed Switches and Final Language per Viewer
- Hotstar: Stage Times of Slow Highlights Clips
- LinkedIn: Applications Year over Year by Company and Quarter
- Meta: Each Reels Creator's Percentile Rank Within Their Country
- Microsoft: Azure Prepayment Balance and Overage Month by Month
- Myntra: The Best Price Box for Each Style Across Three Offers
- Myntra: Each Brand's Three Most-Wishlisted Styles in One Row
- Ola: Driver-Partner Activation and Retention by Approval Month
- Paytm: FASTag Reads Charged Off the Plaza's Axle-Band Rate
- Paytm: Merchant Loan Outstanding as of 31 January 2025
- PhonePe: Three-Way Circular Transfers Within 24 Hours
- Razorpay: Diwali-Week Captured Volume Against Last Year's Diwali Week
- Spotify: Artists Growing Year Over Year in Every Market
- Spotify: Weekly Top 3 Chart With New, Re-Entry, Up and Down Labels
- Swiggy: Third Delivered Order of Each New Customer
- Swiggy: Restaurant Offline Minutes Within Opening Hours
- Swiggy: GMV Report With City Subtotals and a Grand Total
- Uber: Fleet Vehicles on Two Drivers' Shifts at Once
- Uber: Split Fare Shares to the Paisa
- Walmart: Did the Rollback Lift Daily Unit Sales?
- Zomato: Most-Loved Dish of Each Restaurant and Its Complaints
- Zomato: Restaurant Partner Anniversaries Falling in November
- Zomato: Orders Placed While the Restaurant Was Closed
- Zomato: Ratings Before and After a Hygiene Audit