forked from NWC2/SQL-Exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswers.sh
More file actions
112 lines (88 loc) · 1.58 KB
/
answers.sh
File metadata and controls
112 lines (88 loc) · 1.58 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# ex1
SELECT Name
FROM students;
# ex2
SELECT *
FROM students
WHERE Age>30;
# ex3
SELECT Name
FROM students
WHERE Gender="F" AND Age=30;
# ex4
SELECT Points
FROM students
WHERE Name="Alex";
# ex5
INSERT INTO students (ID, Name, Age, Gender, Points)
VALUES (7, "Nancy", 26, "F", 900);
# ex6
UPDATE students
SET Points=Points+40
WHERE Name="Basma";
#ex7
UPDATE students
SET Points=Points-40
WHERE ID=1;
# ex8
# //done
# ex9
# //done
#Creating table graduate
CREATE TABLE graduates (
ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
Name TEXT NOT NULL UNIQUE,
Age INTEGER,
Gender TEXT,
Points INTEGER,
Graduation TEXT
);
# ex10
INSERT INTO graduates(Name, Age, Gender, Points)
SELECT Name, Age, Gender, Points
FROM students
WHERE Name="Layal";
# ex11
UPDATE graduates
SET Graduation="08/09/2018"
WHERE Name="Layal";
# ex12
DELETE FROM students
WHERE Name="Layal";
# ex13
#//done
#ex14
SELECT employees.Name, companies.Name, companies.Date
FROM employees
INNER JOIN companies ON employees.Company=companies.Name;
#ex15
SELECT employees.Name
FROM employees
INNER JOIN companies ON employees.Company=companies.Name
WHERE companies.Date<2000;
# ex16
SELECT companies.Name
FROM companies
INNER JOIN employees ON companies.Name=employees.Company
WHERE employees.Role="Graphic Designer";
#ex17
#//done
#ex18
SELECT Name
FROM students
WHERE Points=(SELECT max(Points) FROM students);
#ex19
SELECT AVG(Points)
FROM students;
#ex20
SELECT count(*)
FROM students
WHERE Points=500;
#ex21
SELECT Name
FROM students
WHERE Name LIKE '%s%';
#ex22
SELECT *
FROM students
ORDER BY Points DESC;