SQL Interview Questions

Relational queries and aggregation.

341 problems

#Title
175Combine Two Tables
176Second Highest Salary
177Nth Highest Salary
178Rank Scores
180Consecutive Numbers
181Employees Earning More Than Their Managers
182Duplicate Emails
183Customers Who Never Order
184Department Highest Salary
185Department Top Three Salaries
192Word Frequency
193Valid Phone Numbers
194Transpose File
195Tenth Line
196Delete Duplicate Emails
197Rising Temperature
262Trips and Users
511Game Play Analysis I
512Game Play Analysis II
534Game Play Analysis III
550Game Play Analysis IV
569Median Employee Salary
570Managers with at Least 5 Direct Reports
571Find Median Given Frequency of Numbers
574Winning Candidate
577Employee Bonus
578Get Highest Answer Rate Question
579Find Cumulative Salary of an Employee
580Count Student Number in Departments
584Find Customer Referee
585Investments in 2016
586Customer Placing the Largest Number of Orders
595Big Countries
596Classes More Than 5 Students
597Friend Requests I: Overall Acceptance Rate
601Human Traffic of Stadium
602Friend Requests II: Who Has the Most Friends
603Consecutive Available Seats
607Sales Person
608Tree Node
610Triangle Judgement
612Shortest Distance in a Plane
613Shortest Distance in a Line
614Second Degree Follower
615Average Salary: Departments VS Company
618Students Report By Geography
619Biggest Single Number
620Not Boring Movies
626Exchange Seats
627Swap Salary
1045Customers Who Bought All Products
1050Actors and Directors Who Cooperated At Least Three Times
1068Product Sales Analysis I
1069Product Sales Analysis II
1070Product Sales Analysis III
1075Project Employees I
1076Project Employees II
1077Project Employees III
1082Sales Analysis I
1083Sales Analysis II
1084Sales Analysis III
1097Game Play Analysis V
1098Unpopular Books
1107New Users Daily Count
1112Highest Grade For Each Student
1113Reported Posts
1126Active Businesses
1127User Purchase Platform
1132Reported Posts II
1141User Activity for the Past 30 Days I
1142User Activity for the Past 30 Days II
1148Article Views I
1149Article Views II
1158Market Analysis I
1159Market Analysis II
1164Product Price at a Given Date
1173Immediate Food Delivery I
1174Immediate Food Delivery II
1179Reformat Department Table
1193Monthly Transactions I
1194Tournament Winners
1204Last Person to Fit in the Elevator
1205Monthly Transactions II
1211Queries Quality and Percentage
1212Team Scores in Football Tournament
1225Report Contiguous Dates
1241Number of Comments per Post
1251Average Selling Price
1264Page Recommendations
1270All People Report to the Given Manager
1280Students and Examinations
1285Find the Start and End Number of Continuous Ranges
1294Weather Type in Each Country
1303Find the Team Size
1308Running Total for Different Genders
1321Restaurant Growth
1322Ads Performance
1327List the Products Ordered in a Period
1336Number of Transactions per Visit
1341Movie Rating
1350Students With Invalid Departments
1355Activity Participants
1364Number of Trusted Contacts of a Customer
1369Get the Second Most Recent Activity
1378Replace Employee ID With The Unique Identifier
1384Total Sales Amount by Year
1393Capital Gain/Loss
1398Customers Who Bought Products A and B but Not C
1407Top Travellers
1412Find the Quiet Students in All Exams
1421NPV Queries
1435Create a Session Bar Chart
1440Evaluate Boolean Expression
1445Apples & Oranges
1454Active Users
1459Rectangles Area
1468Calculate Salaries
1479Sales by Day of the Week
1484Group Sold Products By The Date
1495Friendly Movies Streamed Last Month
1501Countries You Can Safely Invest In
1511Customer Order Frequency
1517Find Users With Valid E-Mails
1527Patients With a Condition
1532The Most Recent Three Orders
1543Fix Product Name Format
1549The Most Recent Orders for Each Product
1555Bank Account Summary
1565Unique Orders and Customers Per Month
1571Warehouse Manager
1581Customer Who Visited but Did Not Make Any Transactions
1587Bank Account Summary II
1596The Most Frequently Ordered Products for Each Customer
1607Sellers With No Sales
1613Find the Missing IDs
1623All Valid Triplets That Can Represent a Country
1633Percentage of Users Attended a Contest
1635Hopper Company Queries I
1645Hopper Company Queries II
1651Hopper Company Queries III
1661Average Time of Process per Machine
1667Fix Names in a Table
1677Product's Worth Over Invoices
1683Invalid Tweets
1693Daily Leads and Partners
1699Number of Calls Between Two Persons
1709Biggest Window Between Visits
1715Count Apples and Oranges
1729Find Followers Count
1731The Number of Employees Which Report to Each Employee
1741Find Total Time Spent by Each Employee
1747Leetflex Banned Accounts
1757Recyclable and Low Fat Products
1767Find the Subtasks That Did Not Execute
1777Product's Price for Each Store
1783Grand Slam Titles
1789Primary Department for Each Employee
1795Rearrange Products Table
1809Ad-Free Sessions
1811Find Interview Candidates
1821Find Customers With Positive Revenue this Year
1831Maximum Transaction Each Day
1841League Statistics
1843Suspicious Bank Accounts
1853Convert Date Format
1867Orders With Maximum Quantity Above Average
1873Calculate Special Bonus
1875Group Employees of the Same Salary
1890The Latest Login in 2020
1892Page Recommendations II
1907Count Salary Categories
1917Leetcodify Friends Recommendations
1919Leetcodify Similar Friends
1934Confirmation Rate
1939Users That Actively Request Confirmation Messages
1949Strong Friendship
1951All the Pairs With the Maximum Number of Common Followers
1965Employees With Missing Information
1972First and Last Call On the Same Day
1978Employees Whose Manager Left the Company
1988Find Cutoff Score for Each School
1990Count the Number of Experiments
2004The Number of Seniors and Juniors to Join the Company
2020Number of Accounts That Did Not Stream
2026Low-Quality Problems
2041Accepted Candidates From the Interviews
2051The Category of Each Member in the Store
2066Account Balance
2072The Winner University
2082The Number of Rich Customers
2084Drop Type 1 Orders for Customers With Type 0 Orders
2112The Airport With the Most Traffic
2118Build the Equation
2142The Number of Passengers in Each Bus I
2153The Number of Passengers in Each Bus II
2159Order Two Columns Independently
2173Longest Winning Streak
2175The Change in Global Rankings
2199Finding the Topic of Each Post
2205The Number of Users That Are Eligible for Discount
2228Users With Two Purchases Within Seven Days
2230The Users That Are Eligible for Discount
2238Number of Times a Driver Was a Passenger
2252Dynamic Pivoting of a Table
2253Dynamic Unpivoting of a Table
2292Products With Three or More Orders in Two Consecutive Years
2298Tasks Count in the Weekend
2308Arrange Table by Gender
2314The First Day of the Maximum Recorded Degree in Each City
2324Product Sales Analysis IV
2329Product Sales Analysis V
2339All the Matches of the League
2346Compute the Rank as a Percentage
2356Number of Unique Subjects Taught by Each Teacher
2362Generate the Invoice
2372Calculate the Influence of Each Salesperson
2377Sort the Olympic Table
2388Change Null Values in a Table to the Previous Value
2394Employees With Deductions
2474Customers With Strictly Increasing Purchases
2480Form a Chemical Bond
2494Merge Overlapping Events in the Same Hall
2504Concatenate the Name and the Profession
2668Find Latest Salaries
2669Count Artist Occurrences On Spotify Ranking List
2686Immediate Food Delivery III
2687Bikes Last Time Used
2688Find Active Users
2701Consecutive Transactions with Increasing Amounts
2720Popularity Percentage
2738Count Occurrences in Text
2752Customers with Maximum Number of Transactions on Consecutive Days
2783Flight Occupancy and Waitlist Analysis
2793Status of Flight Tickets
2820Election Results
2837Total Traveled Distance
2853Highest Salaries Difference
2854Rolling Average Steps
2877Create a DataFrame from List
2878Get the Size of a DataFrame
2879Display the First Three Rows
2880Select Data
2881Create a New Column
2882Drop Duplicate Rows
2883Drop Missing Data
2884Modify Columns
2885Rename Columns
2886Change Data Type
2887Fill Missing Data
2888Reshape Data: Concatenate
2889Reshape Data: Pivot
2890Reshape Data: Melt
2891Method Chaining
2893Calculate Orders Within Each Interval
2922Market Analysis III
2978Symmetric Coordinates
2984Find Peak Calling Hours for Each City
2985Calculate Compressed Mean
2986Find Third Transaction
2987Find Expensive Cities
2988Manager of the Largest Department
2989Class Performance
2990Loan Types
2991Top Three Wineries
2993Friday Purchases I
2994Friday Purchases II
2995Viewers Turned Streamers
3050Pizza Toppings Cost Analysis
3051Find Candidates for Data Scientist Position
3052Maximize Items
3053Classifying Triangles by Lengths
3054Binary Tree Nodes
3055Top Percentile Fraud
3056Snaps Analysis
3057Employees Project Allocation
3058Friends With No Mutual Friends
3059Find All Unique Email Domains
3060User Activities within Time Bounds
3061Calculate Trapping Rain Water
3087Find Trending Hashtags
3089Find Bursty Behavior
3103Find Trending Hashtags II
3118Friday Purchase III
3124Find Longest Calls
3126Server Utilization Time
3140Consecutive Available Seats II
3150Invalid Tweets II
3156Employee Task Duration and Concurrent Tasks
3166Calculate Parking Fees and Duration
3172Second Day Verification
3182Find Top Scoring Students
3188Find Top Scoring Students II
3198Find Cities in Each State
3204Bitwise User Permissions Analysis
3214Year on Year Growth Rate
3220Odd and Even Transactions
3230Customer Purchasing Behavior Analysis
3236CEO Subordinate Hierarchy
3246Premier League Table Ranking
3252Premier League Table Ranking II
3262Find Overlapping Shifts
3268Find Overlapping Shifts II
3278Find Candidates for Data Scientist Position II
3293Calculate Product Final Price
3308Find Top Performing Driver
3322Premier League Table Ranking III
3328Find Cities in Each State II
3338Second Highest Salary II
3358Books with NULL Ratings
3368First Letter Capitalization
3374First Letter Capitalization II
3384Team Dominance by Pass Success
3390Longest Team Pass Streak
3401Find Circular Gift Exchange Chains
3415Find Products with Three Consecutive Digits
3421Find Students Who Improved
3436Find Valid Emails
3451Find Invalid IP Addresses
3465Find Products with Valid Serial Numbers
3475DNA Pattern Recognition
3482Analyze Organization Hierarchy
3497Analyze Subscription Conversion
3521Find Product Recommendation Pairs
3554Find Category Recommendation Pairs
3564Seasonal Sales Analysis
3570Find Books with No Available Copies
3580Find Consistently Improving Employees
3586Find COVID Recovery Patients
3601Find Drivers with Improved Fuel Efficiency
3611Find Overbooked Employees
3617Find Students with Study Spiral Pattern
3626Find Stores with Inventory Imbalance
3642Find Books with Polarized Opinions
3657Find Loyal Customers
3673Find Zombie Sessions
3705Find Golden Hour Customers
3716Find Churn Risk Customers
3764Most Common Course Pairs
3793Find Users with High Token Usage
3808Find Emotionally Consistent Users
3832Find Users with Persistent Behavior Patterns