-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworksheet.sql
94 lines (61 loc) · 1021 Bytes
/
worksheet.sql
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-- Exercise 2
CREATE TABLE [%schema%.]%table% (
%column_name% %data_type% [%option% ...],
...
);
-- Insert
... observers
VALUES ...;
... plots (...)
... (1, 'Control');
-- Foreign key
INSERT INTO ...
... (35550, 789);
-- Basic queries
SELECT ...;
SELECT ...
... animals;
...
FROM ...;
-- Limit
... year, species_id
FROM animals
...;
-- Unique
... species_id
FROM animals;
SELECT ...
FROM animals;
-- Calculated values
... year, month, day, ...
FROM animals;
... plot_id, species_id, sex, weight, ...(weight / 1000.0, ...)
FROM animals;
SELECT plot_id, species_id, sex, weight, ROUND(weight / 1000.0, 2) ...
FROM animals;
-- Exercise 3
...
-- Filtering
SELECT *
FROM animals
...;
SELECT *
FROM animals
...;
SELECT *
FROM animals
WHERE year >= 2000 ...;
SELECT *
FROM animals
WHERE ... AND species_id = 'DM';
-- One-to-many
SELECT ...
FROM animals
... animals.plot_id = plots.id;
-- Many-to-many
SELECT ...
FROM animals
JOIN plots ON animals.plot_id = plots.id
...;
-- Exercise 5
...