Skip to content

Commit f866758

Browse files
committed
Feat: add database solutions
1 parent 24d94c1 commit f866758

9 files changed

+96
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
| 2409 | Count Days Spent Together | [Ruby](./algorithms/ruby/2409-count-days-spent-together.rb) | Easy |
4141
| 2413 | Smallest Even Multiple | [Ruby](./algorithms/ruby/2413-smallest-even-multiple.rb) | Easy |
4242

43+
### Database
44+
| # | Title | Solution | Difficulty |
45+
|---| ----- | -------- | ---------- |
46+
| 175 | Combine Two Tables | [Database](./database/0175-combine-two-tables.sql) | Easy |
47+
| 181 | Employees Earning More Than Their Managers | [Database](./database/0181-employees-earning-more-than-their-managers.sql) | Easy |
48+
| 182 | Duplicate Emails | [Database](./database/0182-duplicate-emails.sql) | Easy |
49+
| 183 | Customers Who Never Order | [Database](./database/0183-customers-who-never-order.sql) | Easy |
50+
| 196 | Delete Duplicate Emails | [Database](./database/0196-delete-duplicate-emails.sql) | Easy |
51+
| 197 | Rising Temperature | [Database](./database/0197-rising-temperature.sql) | Easy |
52+
| 584 | Find Customer Referee | [Database](./database/0584-find-customer-referee.sql) | Easy |
53+
4354
### Shell
4455
| # | Title | Solution | Difficulty |
4556
|---| ----- | -------- | ---------- |

database/0175-combine-two-tables.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Problem: 175. Combine Two Tables
2+
-- URL: https://leetcode.com/problems/combine-two-tables
3+
4+
-- Write your MySQL query statement below
5+
SELECT
6+
firstName,
7+
lastName,
8+
city,
9+
state
10+
FROM
11+
Person
12+
LEFT JOIN Address on Person.personId = Address.personId
13+
;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Problem: 181. Employees Earning More Than Their Managers
2+
-- URL: https://leetcode.com/problems/employees-earning-more-than-their-managers
3+
4+
-- Write your MySQL query statement below
5+
SELECT
6+
a.name AS Employee
7+
FROM
8+
Employee AS a
9+
JOIN Employee AS b ON a.managerId = b.id AND a.salary > b.salary
10+
;

database/0182-duplicate-emails.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Problem: 182. Duplicate Emails
2+
-- URL: https://leetcode.com/problems/duplicate-emails
3+
4+
-- Write your MySQL query statement below
5+
SELECT
6+
email
7+
FROM
8+
Person
9+
group by
10+
email
11+
having count(email) > 1
12+
;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Problem: 183. Customers Who Never Order
2+
-- URL: https://leetcode.com/problems/customers-who-never-order
3+
4+
-- Write your MySQL query statement below
5+
SELECT
6+
name as 'Customers'
7+
FROM
8+
customers
9+
WHERE
10+
id NOT IN
11+
(
12+
SELECT customerid FROM Orders
13+
)
14+
;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Problem: 196. Delete Duplicate Emails
2+
-- URL: https://leetcode.com/problems/delete-duplicate-emails
3+
4+
-- Please write a DELETE statement and DO NOT write a SELECT statement.
5+
-- Write your MySQL query statement below
6+
DELETE
7+
p1
8+
FROM
9+
Person p1, Person p2
10+
WHERE
11+
p1.email = p2.email and p1.id > p2.id
12+
;

database/0197-rising-temperature.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Problem: 197. Rising Temperature
2+
-- URL: https://leetcode.com/problems/rising-temperature
3+
4+
-- Write your MySQL query statement below
5+
SELECT
6+
weather.id AS 'Id'
7+
FROM
8+
weather
9+
JOIN
10+
weather w ON DATEDIFF(weather.recordDate, w.recordDate) = 1
11+
AND weather.temperature > w.temperature
12+
;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Problem: 584. Find Customer Referee
2+
-- URL: https://leetcode.com/problems/find-customer-referee
3+
4+
-- Write your MySQL query statement below
5+
SELECT
6+
name
7+
FROM
8+
Customer
9+
WHERE
10+
referee_id is NULL OR referee_id <> 2
11+
;

0 commit comments

Comments
 (0)