Leetcode-Problems
Leetcode-Problems copied to clipboard
Solved SQL questions in the second round. Aim to organize Multiple solutions and thoughts for each question, compare and find the optimal ones.
Multiple-Solutions-for-Leetcode-Problems
There will be TWO ways to distribute the sql solutions:
- By questions' category - the folders above
- By questions' function - the lists below
Missing value or not exist
Return and state as "null"
| # 1378. Replace Employee ID With The Unique Identi.sql | - |
|---|
Return and state as 0
| # 1142. User Activity for the Past 30 Days II.sql | # 1322. Ads Performance.sql |
|---|---|
| # 1241. Number of Comments per Post.sql | # 1407. Top Travellers.sql |
Return the related column value
| # 1350. Students With Invalid Departments.sql | # 607. Sales Person.sql |
|---|---|
| # 1083. Sales Analysis II.sql | # 1084. Sales Analysis III.sql |
Exist / Sub-query
| # 1549. The Most Recent Orders for Each Product.sql | # 1532. The Most Recent Three Orders.sql |
|---|
Aggregate
Most/Top
| # 1596. The Most Frequently Ordered Products.sql | # 1082. Sales Analysis I.sql |
|---|---|
| # 1076. Project Employees II.sql | # 586. Customer Placing the Largest NO of Order.sql |
| # 619. Biggest Single Number.sql | - |
Return result, and result will be compared "more/less than"
| # 1587. Bank Account Summary II.sql | - |
|---|
As a condition, the result will be compared "more/less than" or "have/not have
return categories from numbers
| # 1294. Weather Type in Each Country.sql | - |
|---|
Include the result, no matter is 0 or not
| # 1280. Students and Examinations.sql | - |
|---|
Others
| # 1303. Find the Team Size.sql | - |
|---|
Calculation
Plus and Minus transaction
| # 1555. Bank Account Summary.sql | # 1445. Apples & Oranges.sql |
|---|
Rate or Percentage
| # 1322. Ads Performance.sql | # 1251. Average Selling Price.sql |
|---|---|
| # 1211. Queries Quality and Percentage.sql | # 1173. Immediate Food Delivery I.sql |
across two or more tables
| # 1571. Warehouse Manager.sql | - |
|---|
odd number
| # 620. Not Boring Movies.sql | - |
|---|
Consecutive Problems
| # 603. Consecutive Available Seats.sql | # 1454. Active Users.sql |
|---|
Others
| # 613. Shortest Distance in a Line.sql | - |
|---|
Mathematical shape
| # 1459. Rectangles Area.sql | - |
|---|
Date
Find a specific month
| # 1511. Customer Order Frequency.sql | # 1294. Weather Type in Each Country.sql |
|---|
Find a specific date/time period
| # 1113. Reported Posts.sql | # 1141. User Activity for the Past 30 Days I.sql |
|---|---|
| # 1084. Sales Analysis III.sql | # 1251. Average Selling Price.sql |
| # 1454. Active Users.sql | - |
Modify into a specific format
| # 1543. Fix Product Name Format.sql | # 1565. Unique Orders and Customers Per Month.sql |
|---|
Most recent date / first date
| # 1549. The Most Recent Orders for Each Product.sql | # 511. Game Play Analysis I.sql |
|---|---|
| # 1532. The Most Recent Three Orders.sql | - |
Case by case
| # 1294. Weather Type in Each Country.sql | # 1322. Ads Performance.sql |
|---|---|
| # 627. Swap Salary.sql | # 610. Triangle Judgement.sql |
Boolean
| # 1440. Evaluate Boolean Expression.sql | - |
|---|
Joins
Three tables
| # 1555. Bank Account Summary.sql | # 1280. Students and Examinations.sql |
|---|---|
| # 1440. Evaluate Boolean Expression.sql | # 1501. Countries You Can Safely Invest In.sql |
| # 1468. Calculate Salaries.sql | - |
Self Joins
| # 1241. Number of Comments per Post.sql | - |
|---|
Formating
aggregate the product names in one cell
| # 1484. Group Sold Products By The Date.sql | - |
|---|
String Validation
| # 1517. Find Users With Valid E-Mails.sql | - |
|---|
- Beginning of the string
- Any upper/lower case chars
- No. of chars
- Range
- accept chars
- end with
String Formay - No lowercase without leading or trailing white spaces
| # 1543. Fix Product Name Format.sql | - |
|---|