File tree 6 files changed +85
-15
lines changed
1900-1999/1965.Employees With Missing Information
6 files changed +85
-15
lines changed Original file line number Diff line number Diff line change 52
52
<li>节点 '2' 是内部节点,因为它有父节点 '1' ,也有孩子节点 '4' 和 '5' 。</li>
53
53
<li>节点 '3', '4' 和 '5' 都是叶子节点,因为它们都有父节点同时没有孩子节点。</li>
54
54
<li>样例中树的形态如下:
55
- <p> </p>
56
-
57
- <pre> 1
55
+ <p> </p>
56
+ <pre> 1
58
57
/ \
59
- 2 3
60
- / \
61
- 4 5
62
-
63
- </pre >
64
-
65
- <p> </p>
58
+ 2 3
59
+ / \
60
+ 4 5
61
+ </pre>
62
+ <p> </p>
66
63
</li>
67
-
68
64
</ul >
69
65
70
66
<p ><strong >注意</strong ></p >
80
76
### ** SQL**
81
77
82
78
``` 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;
84
91
```
85
92
86
93
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -91,7 +91,18 @@ Tree table:
91
91
### ** SQL**
92
92
93
93
``` 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;
95
106
```
96
107
97
108
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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;
Original file line number Diff line number Diff line change @@ -82,7 +82,20 @@ Result table:
82
82
<!-- 这里可写当前语言的特殊实现逻辑 -->
83
83
84
84
``` 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;
86
99
```
87
100
88
101
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -86,7 +86,20 @@ The salary of employee 2 is missing.
86
86
### ** SQL**
87
87
88
88
``` 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;
90
103
```
91
104
92
105
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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;
You can’t perform that action at this time.
0 commit comments