Skip to content

Commit 2b6704b

Browse files
authored
Updated readmes.
1 parent 57c59b7 commit 2b6704b

File tree

4 files changed

+165
-20
lines changed

4 files changed

+165
-20
lines changed

src/main/kotlin/g0101_0200/s0175_combine_two_tables/readme.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,30 @@ SQL Schema
66

77
Table: `Person`
88

9-
+-------------+---------+ | Column Name | Type | +-------------+---------+ | personId | int | | lastName | varchar | | firstName | varchar | +-------------+---------+ personId is the primary key column for this table. This table contains information about the ID of some persons and their first and last names.
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| personId | int |
13+
| lastName | varchar |
14+
| firstName | varchar |
15+
+-------------+---------+
16+
17+
personId is the primary key column for this table.
18+
This table contains information about the ID of some persons and their first and last names.
1019

1120
Table: `Address`
1221

13-
+-------------+---------+ | Column Name | Type | +-------------+---------+ | addressId | int | | personId | int | | city | varchar | | state | varchar | +-------------+---------+ addressId is the primary key column for this table. Each row of this table contains information about the city and state of one person with ID = PersonId.
22+
+-------------+---------+
23+
| Column Name | Type |
24+
+-------------+---------+
25+
| addressId | int |
26+
| personId | int |
27+
| city | varchar |
28+
| state | varchar |
29+
+-------------+---------+
30+
31+
addressId is the primary key column for this table.
32+
Each row of this table contains information about the city and state of one person with ID = PersonId.
1433

1534
Write an SQL query to report the first name, last name, city, and state of each person in the `Person` table. If the address of a `personId` is not present in the `Address` table, report `null` instead.
1635

@@ -20,8 +39,33 @@ The query result format is in the following example.
2039

2140
**Example 1:**
2241

23-
**Input:** Person table: +----------+----------+-----------+ | personId | lastName | firstName | +----------+----------+-----------+ | 1 | Wang | Allen | | 2 | Alice | Bob | +----------+----------+-----------+ Address table: +-----------+----------+---------------+------------+ | addressId | personId | city | state | +-----------+----------+---------------+------------+ | 1 | 2 | New York City | New York | | 2 | 3 | Leetcode | California | +-----------+----------+---------------+------------+
42+
**Input:**
2443

25-
**Output:** +-----------+----------+---------------+----------+ | firstName | lastName | city | state | +-----------+----------+---------------+----------+ | Allen | Wang | Null | Null | | Bob | Alice | New York City | New York | +-----------+----------+---------------+----------+
44+
Person table:
45+
+----------+----------+-----------+
46+
| personId | lastName | firstName |
47+
+----------+----------+-----------+
48+
| 1 | Wang | Allen |
49+
| 2 | Alice | Bob |
50+
+----------+----------+-----------+
51+
52+
Address table:
53+
+-----------+----------+---------------+------------+
54+
| addressId | personId | city | state |
55+
+-----------+----------+---------------+------------+
56+
| 1 | 2 | New York City | New York |
57+
| 2 | 3 | Leetcode | California |
58+
+-----------+----------+---------------+------------+
2659

27-
**Explanation:** There is no address in the address table for the personId = 1 so we return null in their city and state. addressId = 1 contains information about the address of personId = 2.
60+
**Output:**
61+
62+
+-----------+----------+---------------+----------+
63+
| firstName | lastName | city | state |
64+
+-----------+----------+---------------+----------+
65+
| Allen | Wang | Null | Null |
66+
| Bob | Alice | New York City | New York |
67+
+-----------+----------+---------------+----------+
68+
69+
**Explanation:**
70+
71+
There is no address in the address table for the personId = 1 so we return null in their city and state. addressId = 1 contains information about the address of personId = 2.

src/main/kotlin/g0101_0200/s0176_second_highest_salary/readme.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,55 @@ SQL Schema
66

77
Table: `Employee`
88

9-
+-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Each row of this table contains information about the salary of an employee.
9+
+-------------+------+
10+
| Column Name | Type |
11+
+-------------+------+
12+
| id | int |
13+
| salary | int |
14+
+-------------+------+
15+
id is the primary key column for this table.
16+
Each row of this table contains information about the salary of an employee.
1017

1118
Write an SQL query to report the second highest salary from the `Employee` table. If there is no second highest salary, the query should report `null`.
1219

1320
The query result format is in the following example.
1421

1522
**Example 1:**
1623

17-
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+
24+
**Input:**
1825

19-
**Output:** +---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+
26+
Employee table:
27+
+----+--------+
28+
| id | salary |
29+
+----+--------+
30+
| 1 | 100 |
31+
| 2 | 200 |
32+
| 3 | 300 |
33+
+----+--------+
34+
35+
**Output:**
36+
37+
+---------------------+
38+
| SecondHighestSalary |
39+
+---------------------+
40+
| 200 |
41+
+---------------------+
2042

2143
**Example 2:**
2244

23-
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+
45+
**Input:**
46+
47+
Employee table:
48+
+----+--------+
49+
| id | salary |
50+
+----+--------+
51+
| 1 | 100 |
52+
+----+--------+
53+
54+
**Output:**
2455

25-
**Output:** +---------------------+ | SecondHighestSalary | +---------------------+ | null | +---------------------+
56+
+---------------------+
57+
| SecondHighestSalary |
58+
+---------------------+
59+
| null |
60+
+---------------------+

src/main/kotlin/g0101_0200/s0177_nth_highest_salary/readme.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,56 @@ SQL Schema
66

77
Table: `Employee`
88

9-
+-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Each row of this table contains information about the salary of an employee.
9+
+-------------+------+
10+
| Column Name | Type |
11+
+-------------+------+
12+
| id | int |
13+
| salary | int |
14+
+-------------+------+
15+
id is the primary key column for this table. Each row of this table contains information about the salary of an employee.
1016

11-
Write an SQL query to report the <code>n<sup>th</sup></code> highest salary from the `Employee` table. If there is no <code>n<sup>th</sup></code> highest salary, the query should report `null`.
17+
Write an SQL query to report the `nth` highest salary from the `Employee` table. If there is no `nth` highest salary, the query should report `null`.
1218

1319
The query result format is in the following example.
1420

1521
**Example 1:**
1622

17-
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ n = 2
23+
**Input:**
1824

19-
**Output:** +------------------------+ | getNthHighestSalary(2) | +------------------------+ | 200 | +------------------------+
25+
Employee table:
26+
+----+--------+
27+
| id | salary |
28+
+----+--------+
29+
| 1 | 100 |
30+
| 2 | 200 |
31+
| 3 | 300 |
32+
+----+--------+
33+
n = 2
34+
35+
**Output:**
36+
37+
+------------------------+
38+
| getNthHighestSalary(2) |
39+
+------------------------+
40+
| 200 |
41+
+------------------------+
2042

2143
**Example 2:**
2244

23-
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+ n = 2
45+
**Input:**
46+
47+
Employee table:
48+
+----+--------+
49+
| id | salary |
50+
+----+--------+
51+
| 1 | 100 |
52+
+----+--------+
53+
n = 2
54+
55+
**Output:**
2456

25-
**Output:** +------------------------+ | getNthHighestSalary(2) | +------------------------+ | null | +------------------------+
57+
+------------------------+
58+
| getNthHighestSalary(2) |
59+
+------------------------+
60+
| null |
61+
+------------------------+

src/main/kotlin/g0101_0200/s0178_rank_scores/readme.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ SQL Schema
66

77
Table: `Scores`
88

9-
+-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | score | decimal | +-------------+---------+ id is the primary key for this table. Each row of this table contains the score of a game. Score is a floating point value with two decimal places.
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| id | int |
13+
| score | decimal |
14+
+-------------+---------+
15+
id is the primary key for this table.
16+
Each row of this table contains the score of a game. Score is a floating point value with two decimal places.
1017

1118
Write an SQL query to rank the scores. The ranking should be calculated according to the following rules:
1219

@@ -20,6 +27,29 @@ The query result format is in the following example.
2027

2128
**Example 1:**
2229

23-
**Input:** Scores table: +----+-------+ | id | score | +----+-------+ | 1 | 3.50 | | 2 | 3.65 | | 3 | 4.00 | | 4 | 3.85 | | 5 | 4.00 | | 6 | 3.65 | +----+-------+
24-
25-
**Output:** +-------+------+ | score | rank | +-------+------+ | 4.00 | 1 | | 4.00 | 1 | | 3.85 | 2 | | 3.65 | 3 | | 3.65 | 3 | | 3.50 | 4 | +-------+------+
30+
**Input:**
31+
32+
Scores table:
33+
+----+-------+
34+
| id | score |
35+
+----+-------+
36+
| 1 | 3.50 |
37+
| 2 | 3.65 |
38+
| 3 | 4.00 |
39+
| 4 | 3.85 |
40+
| 5 | 4.00 |
41+
| 6 | 3.65 |
42+
+----+-------+
43+
44+
**Output:**
45+
46+
+-------+------+
47+
| score | rank |
48+
+-------+------+
49+
| 4.00 | 1 |
50+
| 4.00 | 1 |
51+
| 3.85 | 2 |
52+
| 3.65 | 3 |
53+
| 3.65 | 3 |
54+
| 3.50 | 4 |
55+
+-------+------+

0 commit comments

Comments
 (0)