Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
CREATE TABLE employees (
employee_id SERIAL PRIMARY KEY,
employee_name VARCHAR(100),
manager_id INTEGER REFERENCES employees(employee_id)
);
INSERT INTO employees (employee_name, manager_id) VALUES
('CEO', NULL),
('Engineering Manager', 1),
('Sales Manager', 1),
('Developer A', 2),
('Developer B', 2),
('Sales Executive', 3);
WITH RECURSIVE organization_chart AS (
SELECT
employee_id,
employee_name,
manager_id,
1 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
SELECT
e.employee_id,
e.employee_name,
e.manager_id,
oc.level + 1
FROM employees e
JOIN organization_chart oc
ON e.manager_id = oc.employee_id
)
SELECT *
FROM organization_chart
ORDER BY level, employee_name;Coding works best on desktop or with an external keyboard.
~`
!1
@2
#3
$4
%5
^6
&7
*8
(9
)0
_-
+=
⌫
Tab
Q
W
E
R
T
Y
U
I
O
P
{[
}]
|\
Caps
A
S
D
F
G
H
J
K
L
:;
"'
↵
⇧
Z
X
C
V
B
N
M
<,
>.
?/
⇧
Ctrl
⊞
Alt
␣
Alt
⊞
Ctx
Ctrl
👈Middle
CL Pinky
L Ring
L Middle
L Index
Thumb
R Index
R Middle
R Ring
R Pinky