Skip to main content

LeetCode SQL Problems by Problem Domain

Useful Reference

Summer 2021

Best problems

  • LC 586. Customer Placing the Largest Number of Orders
  • LC 601. Human Traffic of Stadium
  • LC 608. Tree Node
  • LC 615. Average Salary: Departments VS Company
  • LC 618. Students Report By Geography
  • LC 1045. Customers Who Bought All Products
  • LC 1126. Active Businesses
  • LC 1127. User Purchase Platform
  • LC 1159. Market Analysis II
  • LC 1179. Reformat Department Table
  • LC 1212. Team Scores in Football Tournament
  • LC 1225. Report Contiguous Dates
  • LC 1321. Restaurant Growth
  • LC 1341. Movie Rating
  • LC 1369. Get the Second Most Recent Activity
  • LC 1384. Total Sales Amount by Year
  • LC 1454. Active Users
  • LC 1468. Calculate Salaries
  • LC 1596. The Most Frequently Ordered Products for Each Customer
  • LC 1613. Find the Missing IDs
  • LC 1811. Find Interview Candidates

Good problems

Revisit

Beginner problems

  • LC 175. Combine Two Tables
  • LC 182. Duplicate Emails
  • LC 511. Game Play Analysis I
  • LC 577. Employee Bonus
  • LC 580. Count Student Number in Departments
  • LC 584. Find Customer Referee
  • LC 595. Big Countries
  • LC 620. Not Boring Movies
  • LC 1068. Product Sales Analysis I
  • LC 1069. Product Sales Analysis II
  • LC 1075. Project Employees I
  • LC 1113. Reported Posts
  • LC 1148. Article Views I
  • LC 1294. Weather Type in Each Country
  • LC 1327. List the Products Ordered in a Period
  • LC 1350. Students With Invalid Departments
  • LC 1378. Replace Employee ID With The Unique Identifier
  • LC 1407. Top Travellers
  • LC 1587. Bank Account Summary II
  • LC 1683. Invalid Tweets
  • LC 1693. Daily Leads and Partners
  • LC 1757. Recyclable and Low Fat Products
  • LC 1821. Find Customers With Positive Revenue this Year

CASE statements

Correlated subquery

Dates and timestamps

  • LC 197. Rising Temperature
  • LC 1084. Sales Analysis III
  • LC 1193. Monthly Transactions I
  • LC 1384. Total Sales Amount by Year
  • LC 1454. Active Users
  • LC 1543. Fix Product Name Format

DELETE

DISTINCT

  • LC 596. Classes More Than 5 Students
  • LC 1149. Article Views II

EXISTS and NOT EXISTS

Gaps and islands

  • LC 180. Consecutive Numbers
  • LC 601. Human Traffic of Stadium
  • LC 603. Consecutive Available Seats
  • LC 1225. Report Contiguous Dates
  • LC 1285. Find the Start and End Number of Continuous Ranges
  • LC 1454. Active Users

IN and NOT IN

Indicator variables

Joins

Cross-joins

LEFT JOIN

  • LC 175. Combine Two Tables
  • LC 183. Customers Who Never Order
  • LC 1158. Market Analysis I

Non-equi-joins

RIGHT JOIN

Self-joins

Median

NOT EXISTS (see EXISTS)

NOT IN (see IN)

NULL values and effective management

  • LC 176. Second Highest Salary
  • LC 584. Find Customer Referee
  • LC 608. Tree Node
  • LC 1098. Unpopular Books

Pivoting

Result set to multiple rows

Recursive CTEs

Regular expressions

Stored procedures

  • LC 177. Nth Highest Salary

UNION and UNION ALL

UPDATE

Window functions

Named windows

AVG()

COUNT()

DENSE_RANK()

  • LC 178. Rank Scores
  • LC 184. Department Highest Salary
  • LC 185. Department Top Three Salaries
  • LC 1341. Movie Rating

LAG()

LEAD()

MAX()

MIN()

PERCENTILE_CONT()

RANK()

ROW_NUMBER()

SUM()

With GROUP BY (ORDER BY aggregate)