Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL 50: Data Analyst Interview Prep

This is a walkthrough of the 50 SQL problems that show up most often when people prep for data analyst, BI, and data analytics intern interviews. It's based on LeetCode's free "SQL 50" study plan, and every solution here is written in MySQL.

progress

Structure

sql-50-data-analyst-interview-prep/
├── README.md
├── LICENSE
├── STUDY_GUIDE.md
├── PROGRESS.md
└── solutions/
    ├── 01-filtering/
    │   ├── 1757-recyclable-and-low-fat-products.sql
    │   ├── 584-find-customer-referee.sql
    │   ├── 595-big-countries.sql
    │   ├── 1148-article-views-i.sql
    │   ├── 1683-invalid-tweets.sql
    │   ├── 620-not-boring-movies.sql
    │   ├── 610-triangle-judgement.sql
    │   ├── 1527-patients-with-a-condition.sql
    │   ├── 1667-fix-names-in-a-table.sql
    │   └── 1517-find-users-with-valid-e-mails.sql
    ├── 02-joins/
    │   ├── 1378-replace-employee-id-with-the-unique-identifier.sql
    │   ├── 1068-product-sales-analysis-i.sql
    │   ├── 1581-customer-who-visited-but-did-not-make-any-transactions.sql
    │   ├── 577-employee-bonus.sql
    │   ├── 1280-students-and-examinations.sql
    │   ├── 1075-project-employees-i.sql
    │   ├── 1731-the-number-of-employees-which-report-to-each-employee.sql
    │   └── 196-delete-duplicate-emails.sql
    ├── 03-aggregation/
    │   ├── 570-managers-with-at-least-5-direct-reports.sql
    │   ├── 596-classes-more-than-5-students.sql
    │   ├── 1729-find-followers-count.sql
    │   ├── 619-biggest-single-number.sql
    │   ├── 1045-customers-who-bought-all-products.sql
    │   ├── 2356-number-of-unique-subjects-taught-by-each-teacher.sql
    │   ├── 1484-group-sold-products-by-the-date.sql
    │   ├── 1327-list-the-products-ordered-in-a-period.sql
    │   ├── 1907-count-salary-categories.sql
    │   └── 585-investments-in-2016.sql
    ├── 04-subqueries/
    │   ├── 176-second-highest-salary.sql
    │   ├── 185-department-top-three-salaries.sql
    │   ├── 197-rising-temperature.sql
    │   ├── 180-consecutive-numbers.sql
    │   ├── 1070-product-sales-analysis-iii.sql
    │   ├── 1164-product-price-at-a-given-date.sql
    │   ├── 1789-primary-department-for-each-employee.sql
    │   └── 1978-employees-whose-manager-left-the-company.sql
    ├── 05-string-date-functions/
    │   ├── 1661-average-time-of-process-per-machine.sql
    │   ├── 1193-monthly-transactions-i.sql
    │   ├── 1141-user-activity-for-the-past-30-days-i.sql
    │   ├── 1211-queries-quality-and-percentage.sql
    │   ├── 1633-percentage-of-users-attended-a-contest.sql
    │   └── 1251-average-selling-price.sql
    └── 06-window-functions/
        ├── 1934-confirmation-rate.sql
        ├── 1174-immediate-food-delivery-ii.sql
        ├── 550-game-play-analysis-iv.sql
        ├── 1204-last-person-to-fit-in-the-bus.sql
        ├── 626-exchange-seats.sql
        ├── 1341-movie-rating.sql
        ├── 1321-restaurant-growth.sql
        └── 602-friend-requests-ii-who-has-the-most-friends.sql

Problems by category

Basic Filtering & SELECT

# Problem Difficulty LeetCode File
1 Recyclable and Low Fat Products Easy 1757 1757-recyclable-and-low-fat-products.sql
2 Find Customer Referee Easy 584 584-find-customer-referee.sql
3 Big Countries Easy 595 595-big-countries.sql
4 Article Views I Easy 1148 1148-article-views-i.sql
5 Invalid Tweets Easy 1683 1683-invalid-tweets.sql
6 Not Boring Movies Easy 620 620-not-boring-movies.sql
7 Triangle Judgement Easy 610 610-triangle-judgement.sql
8 Patients With a Condition Easy 1527 1527-patients-with-a-condition.sql
9 Fix Names in a Table Easy 1667 1667-fix-names-in-a-table.sql
10 Find Users With Valid E-Mails Easy 1517 1517-find-users-with-valid-e-mails.sql

Joins

# Problem Difficulty LeetCode File
11 Replace Employee ID With The Unique Identifier Easy 1378 1378-replace-employee-id-with-the-unique-identifier.sql
12 Product Sales Analysis I Easy 1068 1068-product-sales-analysis-i.sql
13 Customer Who Visited but Did Not Make Any Transactions Easy 1581 1581-customer-who-visited-but-did-not-make-any-transactions.sql
14 Employee Bonus Easy 577 577-employee-bonus.sql
15 Students and Examinations Easy 1280 1280-students-and-examinations.sql
16 Project Employees I Easy 1075 1075-project-employees-i.sql
17 The Number of Employees Which Report to Each Employee Easy 1731 1731-the-number-of-employees-which-report-to-each-employee.sql
18 Delete Duplicate Emails Easy 196 196-delete-duplicate-emails.sql

Aggregation, GROUP BY & HAVING

# Problem Difficulty LeetCode File
19 Managers with at Least 5 Direct Reports Medium 570 570-managers-with-at-least-5-direct-reports.sql
20 Classes More Than 5 Students Easy 596 596-classes-more-than-5-students.sql
21 Find Followers Count Easy 1729 1729-find-followers-count.sql
22 Biggest Single Number Easy 619 619-biggest-single-number.sql
23 Customers Who Bought All Products Medium 1045 1045-customers-who-bought-all-products.sql
24 Number of Unique Subjects Taught by Each Teacher Easy 2356 2356-number-of-unique-subjects-taught-by-each-teacher.sql
25 Group Sold Products By The Date Easy 1484 1484-group-sold-products-by-the-date.sql
26 List the Products Ordered in a Period Easy 1327 1327-list-the-products-ordered-in-a-period.sql
27 Count Salary Categories Medium 1907 1907-count-salary-categories.sql
28 Investments in 2016 Medium 585 585-investments-in-2016.sql

Subqueries & Advanced SELECT

# Problem Difficulty LeetCode File
29 Second Highest Salary Medium 176 176-second-highest-salary.sql
30 Department Top Three Salaries Hard 185 185-department-top-three-salaries.sql
31 Rising Temperature Easy 197 197-rising-temperature.sql
32 Consecutive Numbers Medium 180 180-consecutive-numbers.sql
33 Product Sales Analysis III Medium 1070 1070-product-sales-analysis-iii.sql
34 Product Price at a Given Date Medium 1164 1164-product-price-at-a-given-date.sql
35 Primary Department for Each Employee Easy 1789 1789-primary-department-for-each-employee.sql
36 Employees Whose Manager Left the Company Easy 1978 1978-employees-whose-manager-left-the-company.sql

String, Date & Formatting Functions

# Problem Difficulty LeetCode File
37 Average Time of Process per Machine Easy 1661 1661-average-time-of-process-per-machine.sql
38 Monthly Transactions I Medium 1193 1193-monthly-transactions-i.sql
39 User Activity for the Past 30 Days I Easy 1141 1141-user-activity-for-the-past-30-days-i.sql
40 Queries Quality and Percentage Easy 1211 1211-queries-quality-and-percentage.sql
41 Percentage of Users Attended a Contest Easy 1633 1633-percentage-of-users-attended-a-contest.sql
42 Average Selling Price Easy 1251 1251-average-selling-price.sql

Window Functions & Advanced Analytics

# Problem Difficulty LeetCode File
43 Confirmation Rate Medium 1934 1934-confirmation-rate.sql
44 Immediate Food Delivery II Medium 1174 1174-immediate-food-delivery-ii.sql
45 Game Play Analysis IV Medium 550 550-game-play-analysis-iv.sql
46 Last Person to Fit in the Bus Medium 1204 1204-last-person-to-fit-in-the-bus.sql
47 Exchange Seats Medium 626 626-exchange-seats.sql
48 Movie Rating Medium 1341 1341-movie-rating.sql
49 Restaurant Growth Medium 1321 1321-restaurant-growth.sql
50 Friend Requests II: Who Has the Most Friends Medium 602 602-friend-requests-ii-who-has-the-most-friends.sql

How to use this repo

  • Each .sql file stands on its own: the schema, the task, a working solution, and a short explanation, all written as comments around one runnable query.
  • Try solving the problem yourself first, ideally on LeetCode's Database problem set, then compare your answer against the file here.
  • STUDY_GUIDE.md covers interview tips and a suggested order to work through the topics.
  • PROGRESS.md is just a plain checklist. Fork it and check things off as you go.

License

MIT. See LICENSE for details.

About

Solutions and explanations for the 50 SQL questions most used to prep for data analyst & BI intern interviews. MySQL syntax, organized by topic.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors