Skip to content

Commit 33602db

Browse files
committed
feat: add sql solution to lc problems: No.0608,01965
- No.0608.Tree Node - No.1965.Employees With Missing Information
1 parent e0c4a4e commit 33602db

File tree

6 files changed

+85
-15
lines changed

6 files changed

+85
-15
lines changed

solution/0600-0699/0608.Tree Node/README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,15 @@
5252
<li>节点 &#39;2&#39; 是内部节点,因为它有父节点 &#39;1&#39; ,也有孩子节点 &#39;4&#39; 和 &#39;5&#39; 。</li>
5353
<li>节点 &#39;3&#39;, &#39;4&#39; 和 &#39;5&#39; 都是叶子节点,因为它们都有父节点同时没有孩子节点。</li>
5454
<li>样例中树的形态如下:
55-
<p>&nbsp;</p>
56-
57-
<pre> 1
55+
<p>&nbsp;</p>
56+
<pre> 1
5857
/ \
59-
2 3
60-
/ \
61-
4 5
62-
63-
</pre>
64-
65-
<p>&nbsp;</p>
58+
2 3
59+
/ \
60+
4 5
61+
</pre>
62+
<p>&nbsp;</p>
6663
</li>
67-
6864
</ul>
6965

7066
<p><strong>注意</strong></p>
@@ -80,7 +76,18 @@
8076
### **SQL**
8177

8278
```sql
83-
79+
SELECT id,
80+
(
81+
CASE
82+
WHEN p_id IS NULL THEN 'Root'
83+
WHEN id IN (
84+
SELECT p_id
85+
FROM tree
86+
) THEN 'Inner'
87+
ELSE 'Leaf'
88+
END
89+
) AS type
90+
FROM tree;
8491
```
8592

8693
<!-- tabs:end -->

solution/0600-0699/0608.Tree Node/README_EN.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,18 @@ Tree table:
9191
### **SQL**
9292

9393
```sql
94-
94+
SELECT id,
95+
(
96+
CASE
97+
WHEN p_id IS NULL THEN 'Root'
98+
WHEN id IN (
99+
SELECT p_id
100+
FROM tree
101+
) THEN 'Inner'
102+
ELSE 'Leaf'
103+
END
104+
) AS type
105+
FROM tree;
95106
```
96107

97108
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT id,
2+
(
3+
CASE
4+
WHEN p_id IS NULL THEN 'Root'
5+
WHEN id IN (
6+
SELECT p_id
7+
FROM tree
8+
) THEN 'Inner'
9+
ELSE 'Leaf'
10+
END
11+
) AS type
12+
FROM tree;

solution/1900-1999/1965.Employees With Missing Information/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,20 @@ Result table:
8282
<!-- 这里可写当前语言的特殊实现逻辑 -->
8383

8484
```sql
85-
85+
SELECT employee_id
86+
FROM Employees AS e
87+
WHERE e.employee_id NOT IN (
88+
SELECT employee_id
89+
FROM Salaries
90+
)
91+
UNION
92+
SELECT employee_id
93+
FROM Salaries AS s
94+
WHERE s.employee_id NOT IN (
95+
SELECT employee_id
96+
FROM Employees
97+
)
98+
ORDER BY employee_id;
8699
```
87100

88101
<!-- tabs:end -->

solution/1900-1999/1965.Employees With Missing Information/README_EN.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,20 @@ The salary of employee 2 is missing.
8686
### **SQL**
8787

8888
```sql
89-
89+
SELECT employee_id
90+
FROM Employees AS e
91+
WHERE e.employee_id NOT IN (
92+
SELECT employee_id
93+
FROM Salaries
94+
)
95+
UNION
96+
SELECT employee_id
97+
FROM Salaries AS s
98+
WHERE s.employee_id NOT IN (
99+
SELECT employee_id
100+
FROM Employees
101+
)
102+
ORDER BY employee_id;
90103
```
91104

92105
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SELECT employee_id
2+
FROM Employees AS e
3+
WHERE e.employee_id NOT IN (
4+
SELECT employee_id
5+
FROM Salaries
6+
)
7+
UNION
8+
SELECT employee_id
9+
FROM Salaries AS s
10+
WHERE s.employee_id NOT IN (
11+
SELECT employee_id
12+
FROM Employees
13+
)
14+
ORDER BY employee_id;

0 commit comments

Comments
 (0)