An open API service indexing awesome lists of open source software.

https://github.com/ivanbyone/awesome-leetcode-sql

LeetCode SQL Solutions in PostgreSQL
https://github.com/ivanbyone/awesome-leetcode-sql

List: awesome-leetcode-sql

awesome-sql interview-preparation leetcode leetcode-solutions leetcode-sql leetcode-sql-50 pgsql postgresql sql

Last synced: 4 months ago
JSON representation

LeetCode SQL Solutions in PostgreSQL

Awesome Lists containing this project

README

          

# Leetcode (PostgreSQL)

![Postgres](https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white)
[![MIT licensed](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
[![CI](https://github.com/ivanbyone/leetcode-sql/actions/workflows/ci.yml/badge.svg)](https://github.com/Ivanbyone/leetcode-sql//actions)

## Navigation

- [Description](#description)
- [SQL 50](#sql-50-questions)
- [All Tasks list](#all-tasks-list)
- [Contributing](#contributing)
- [License](#license)

## Description

📚 LeetCode SQL Solutions in PostgreSQL

A collection of LeetCode solutions in SQL using PostgreSQL. Includes:
- Easy/Medium/Hard solutions
- Optimized queries

🔹 Features:
- Clean, formatted SQL code
- Use of PostgreSQL-specific functions
- Parsing complex queries
- Regular updates

Useful for preparing for technical interviews and improving your SQL skills.

## SQL 50 Questions

![SQL 50 Badge](./public/sql-50.GIF)

### Select

- [595. Big Countries](./leetcode/easy/595.%20Big%20Countries.sql)
- [1148. Article Views I](./leetcode/easy/1148.%20Article%20Views%20I.sql)
- [1683. Invalid Tweets](./leetcode/easy/1683.%20Invalid%20Tweets.sql)

### Basic Joins

- [1378. Replace Employee ID With The Unique Identifier](./leetcode/easy/1378.%20Replace%20Employee%20ID%20With%20The%20Unique%20Identifier.sql)
- [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql)
- [1581. Customer Who Visited but Did Not Make Any Transactions](./leetcode/easy/1581.%20Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions.sql)
- [197. Rising Temperature](./leetcode/easy/197.%20Rising%20Temperature.sql)
- [1661. Average Time of Process per Machine](./leetcode/easy/1661.%20Average%20Time%20of%20Process%20per%20Machine.sql)
- [577. Employee Bonus](./leetcode/easy/577.%20Employee%20Bonus.sql)
- [1280. Students and Examinations](./leetcode/easy/1280.%20Students%20and%20Examinations.sql)
- [570. Managers with at Least 5 Direct Reports](./leetcode/medium/570.%20Managers%20with%20at%20Least%205%20Direct%20Reports.sql)
- [1934. Confirmation Rate](./leetcode/medium/1934.%20Confirmation%20Rate.sql)

### Basic Aggregate Functions

- [620. Not Boring Movies](./leetcode/easy/620.%20Not%20Boring%20Movies.sql)
- [1251. Average Selling Price](./leetcode/easy/1251.%20Average%20Selling%20Price.sql)
- [1075. Project Employees I](./leetcode/easy/1075.%20Project%20Employees%20I.sql)
- [1633. Percentage of Users Attended a Contest](./leetcode/easy/1633.%20Percentage%20of%20Users%20Attended%20a%20Contest.sql)
- [1211. Queries Quality and Percentage](./leetcode/easy/1211.%20Queries%20Quality%20and%20Percentage.sql)
- [1193. Monthly Transactions I](./leetcode/medium/1193.%20Monthly%20Transactions%20I.sql)
- [1174. Immediate Food Delivery II](./leetcode/medium/1174.%20Immediate%20Food%20Delivery%20II.sql)
- [550. Game Play Analysis IV](./leetcode/medium/550.%20Game%20Play%20Analysis%20IV.sql)

### Sorting and Grouping

- [2356. Number of Unique Subjects Taught by Each Teacher](./leetcode/easy/2356.%20Number%20of%20Unique%20Subjects%20Taught%20by%20Each%20Teacher.sql)
- [1141. User Activity for the Past 30 Days I](./leetcode/easy/1141.%20User%20Activity%20for%20the%20Past%2030%20Days%20I.sql)
- [1070. Product Sales Analysis III](./leetcode/medium/1070.%20Product%20Sales%20Analysis%203.sql)
- [596. Classes With at Least 5 Students](./leetcode/easy/596.%20Classes%20With%20at%20Least%205%20Students.sql)
- [1729. Find Followers Count](./leetcode/easy/1729.%20Find%20Followers%20Count.sql)
- [619. Biggest Single Number](./leetcode/easy/619.%20Biggest%20Single%20Number.sql)
- [1045. Customers Who Bought All Products](./leetcode/medium/1045.%20Customers%20Who%20Bought%20All%20Products.sql)

### Advanced Select and Joins

- [1731. The Number of Employees Which Report to Each Employee](./leetcode/easy/1731.%20The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee.sql)
- [1789. Primary Department for Each Employee](./leetcode/easy/1789.%20Primary%20Department%20for%20Each%20Employee.sql)
- [610. Triangle Judgement](./leetcode/easy/610.%20Triangle%20Judgement.sql)
- [180. Consecutive Numbers](./leetcode/medium/180.%20Consecutive%20Numbers.sql)
- [1164. Product Price at a Given Date](./leetcode/medium/1164.%20Product%20Price%20at%20a%20Given%20Date.sql)
- [1204. Last Person to Fit in the Bus](./leetcode/medium/1204.%20Last%20Person%20to%20Fit%20in%20the%20Bus.sql)
- [1907. Count Salary Categories](./leetcode/medium/1907.%20Count%20Salary%20Categories.sql)

### Subqueries

- [1978. Employees Whose Manager Left the Company](./leetcode/easy/1978.%20Employees%20Whose%20Manager%20Left%20the%20Company.sql)
- [626. Exchange Seats](./leetcode/medium/626.%20Exchange%20Seats.sql)
- [1321. Restaurant Growth](./leetcode/medium/1321.%20Restaurant%20Growth.sql)
- [1341. Movie Rating](./leetcode/medium/1341.%20Movie%20Rating.sql)
- [602. Friend Requests II: Who Has the Most Friends](./leetcode/medium/602.%20Friend%20Requests%20II:%20Who%20Has%20the%20Most%20Friends.sql)
- [585. Investments in 2016](./leetcode/medium/585.%20Investments%20in%202016.sql)
- [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql)

### Advanced String Functions / Regex / Clause

- [1667. Fix Names in a Table](./leetcode/easy/1667.%20Fix%20Names%20in%20a%20Table.sql)
- [1527. Patients With a Condition](./leetcode/easy/1527.%20Patients%20With%20a%20Condition.sql)
- [176. Second Highest Salary](./leetcode/medium/176.%20Second%20Highest%20Salary.sql)
- [1484. Group Sold Products By The Date](./leetcode/easy/1484.%20Group%20Sold%20Products%20By%20The%20Date.sql)
- [196. Delete Duplicate Emails](./leetcode/easy/196.%20Delete%20Duplicate%20Emails.sql)
- [1327. List the Products Ordered in a Period](./leetcode/easy/1327.%20List%20the%20Products%20Ordered%20in%20a%20Period.sql)
- [1517. Find Users With Valid E-Mails](./leetcode/easy/1517.%20Find%20Users%20With%20Valid%20E-Mails.sql)

## All Tasks List

1. [Easy](./leetcode/easy/)
- [175. Combine Two Tables](./leetcode//easy/175.%20Combine%20Two%20Tables.sql)
- [181. Employees Earning More Than Their Managers](./leetcode/easy/181.%20Employees%20Earning%20More%20Than%20Their%20Managers.sql)
- [182. Duplicate Emails](./leetcode/easy/182.%20Duplicate%20Emails.sql)
- [183. Customers Who Never Order](./leetcode/easy/183.%20Customers%20Who%20Never%20Order.sql)
- [196. Delete Duplicate Emails](./leetcode/easy/196.%20Delete%20Duplicate%20Emails.sql)
- [197. Rising Temperature](./leetcode/easy/197.%20Rising%20Temperature.sql)
- [511. Game Play Analysis 1](./leetcode/easy/511.%20Game%20Play%20Analysis%201.sql)
- [577. Employee Bonus](./leetcode/easy/577.%20Employee%20Bonus.sql)
- [586. Customer Placing the Largest Number of Orders](./leetcode/easy/586.%20Customer%20Placing%20the%20Largest%20Number%20of%20Orders.sql)
- [595. Big Countries](./leetcode/easy/595.%20Big%20Countries.sql)
- [596. Classes With at Least 5 Students](./leetcode/easy/596.%20Classes%20With%20at%20Least%205%20Students.sql)
- [607. Sales Person](./leetcode/easy/607.%20Sales%20Person.sql)
- [610. Triangle Judgement](./leetcode/easy/610.%20Triangle%20Judgement.sql)
- [619. Biggest Single Number](./leetcode/easy/619.%20Biggest%20Single%20Number.sql)
- [620. Not Boring Movies](./leetcode/easy/620.%20Not%20Boring%20Movies.sql)
- [627. Swap Salary](./leetcode/easy/627.%20Swap%20Salary.sql)
- [1050. Actors and Directors Who Cooperated At Least Three Times](./leetcode/easy/1050.%20Actors%20and%20Directors%20Who%20Cooperated%20At%20Least%20Three%20Times.sql)
- [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql)
- [1075. Project Employees I](./leetcode/easy/1075.%20Project%20Employees%20I.sql)
- [1141. User Activity for the Past 30 Days I](./leetcode/easy/1141.%20User%20Activity%20for%20the%20Past%2030%20Days%20I.sql)
- [1148. Article Views I](./leetcode/easy/1148.%20Article%20Views%20I.sql)
- [1179. Reformat Department Table](./leetcode/easy/1179.%20Reformat%20Department%20Table.sql)
- [1211. Queries Quality and Percentage](./leetcode/easy/1211.%20Queries%20Quality%20and%20Percentage.sql)
- [1251. Average Selling Price](./leetcode/easy/1251.%20Average%20Selling%20Price.sql)
- [1280. Students and Examinations](./leetcode/easy/1280.%20Students%20and%20Examinations.sql)
- [1327. List the Products Ordered in a Period](./leetcode/easy/1327.%20List%20the%20Products%20Ordered%20in%20a%20Period.sql)
- [1378. Replace Employee ID With The Unique Identifier](./leetcode/easy/1378.%20Replace%20Employee%20ID%20With%20The%20Unique%20Identifier.sql)
- [1407. Top Travellers](./leetcode/easy/1407.%20Top%20Travellers.sql)
- [1484. Group Sold Products By The Date](./leetcode/easy/1484.%20Group%20Sold%20Products%20By%20The%20Date.sql)
- [1517. Find Users With Valid E-Mails](./leetcode/easy/1517.%20Find%20Users%20With%20Valid%20E-Mails.sql)
- [1527. Patients With a Condition](./leetcode/easy/1527.%20Patients%20With%20a%20Condition.sql)
- [1581. Customer Who Visited but Did Not Make Any Transactions](./leetcode/easy/1581.%20Customer%20Who%20Visited%20but%20Did%20Not%20Make%20Any%20Transactions.sql)
- [1587. Bank Account Summary II](./leetcode/easy/1587.%20Bank%20Account%20Summary%20II.sql)
- [1633. Percentage of Users Attended a Contest](./leetcode/easy/1633.%20Percentage%20of%20Users%20Attended%20a%20Contest.sql)
- [1661. Average Time of Process per Machine](./leetcode/easy/1661.%20Average%20Time%20of%20Process%20per%20Machine.sql)
- [1667. Fix Names in a Table](./leetcode/easy/1667.%20Fix%20Names%20in%20a%20Table.sql)
- [1683. Invalid Tweets](./leetcode/easy/1683.%20Invalid%20Tweets.sql)
- [1693. Daily Leads and Partners](./leetcode/easy/1693.%20Daily%20Leads%20and%20Partners.sql)
- [1729. Find Followers Count](./leetcode/easy/1729.%20Find%20Followers%20Count.sql)
- [1731. The Number of Employees Which Report to Each Employee](./leetcode/easy/1731.%20The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee.sql)
- [1741. Find Total Time Spent by Each Employee](./leetcode/easy/1741.%20Find%20Total%20Time%20Spent%20by%20Each%20Employee.sql)
- [1789. Primary Department for Each Employee](./leetcode/easy/1789.%20Primary%20Department%20for%20Each%20Employee.sql)
- [1795. Rearrange Products Table](./leetcode/easy/1795.%20Rearrange%20Products%20Table.sql)
- [1873. Calculate Special Bonus](./leetcode/easy/1873.%20Calculate%20Special%20Bonus.sql)
- [1890. The Latest Login in 2020](./leetcode/easy/1890.%20The%20Latest%20Login%20in%202020.sql)
- [1965. Employees With Missing Information](./leetcode/easy/1965.%20Employees%20With%20Missing%20Information.sql)
- [1978. Employees Whose Manager Left the Company](./leetcode/easy/1978.%20Employees%20Whose%20Manager%20Left%20the%20Company.sql)
- [2356. Number of Unique Subjects Taught by Each Teacher](./leetcode/easy/2356.%20Number%20of%20Unique%20Subjects%20Taught%20by%20Each%20Teacher.sql)
- [3436. Find Valid Emails](./leetcode/easy/3436.%20Find%20Valid%20Emails.sql)
2. [Medium](./leetcode/medium/)
- [176. Second Highest Salary](./leetcode/medium/176.%20Second%20Highest%20Salary.sql)
- [180. Consecutive Numbers](./leetcode/medium/180.%20Consecutive%20Numbers.sql)
- [184. Department Highest Salary](./leetcode/medium/184.%20Department%20Highest%20Salary.sql)
- [550. Game Play Analysis IV](./leetcode/medium/550.%20Game%20Play%20Analysis%20IV.sql)
- [570. Managers with at Least 5 Direct Reports](./leetcode/medium/570.%20Managers%20with%20at%20Least%205%20Direct%20Reports.sql)
- [585. Investments in 2016](./leetcode/medium/585.%20Investments%20in%202016.sql)
- [602. Friend Requests II: Who Has the Most Friends](./leetcode/medium/602.%20Friend%20Requests%20II:%20Who%20Has%20the%20Most%20Friends.sql)
- [626. Exchange Seats](./leetcode/medium/626.%20Exchange%20Seats.sql)
- [1045. Customers Who Bought All Products](./leetcode/medium/1045.%20Customers%20Who%20Bought%20All%20Products.sql)
- [1070. Product Sales Analysis III](./leetcode/medium/1070.%20Product%20Sales%20Analysis%203.sql)
- [1158. Market Analysis 1](./leetcode/medium/1158.%20Market%20Analysis%201.sql)
- [1164. Product Price at a Given Date](./leetcode/medium/1164.%20Product%20Price%20at%20a%20Given%20Date.sql)
- [1174. Immediate Food Delivery II](./leetcode/medium/1174.%20Immediate%20Food%20Delivery%20II.sql)
- [1193. Monthly Transactions I](./leetcode/medium/1193.%20Monthly%20Transactions%20I.sql)
- [1204. Last Person to Fit in the Bus](./leetcode/medium/1204.%20Last%20Person%20to%20Fit%20in%20the%20Bus.sql)
- [1321. Restaurant Growth](./leetcode/medium/1321.%20Restaurant%20Growth.sql)
- [1341. Movie Rating](./leetcode/medium/1341.%20Movie%20Rating.sql)
- [1907. Count Salary Categories](./leetcode/medium/1907.%20Count%20Salary%20Categories.sql)
- [1934. Confirmation Rate](./leetcode/medium/1934.%20Confirmation%20Rate.sql)
3. [Hard](./leetcode/hard/)
- [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql)

## Contributing

Style guide for contributors:

1. Add description to all tasks from Leetcode.
2. Name file pattern: xxx.Task name.sql
3. All keywords must be uppercase.
4. For every task create new branch with pattern: task/task-id -> make PR to main.

Have a good contributing!

## License

Check out LICENSE [page](./LICENSE).