forked from Codi-T02/SQL-Exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswers.sh
More file actions
116 lines (88 loc) · 1.76 KB
/
answers.sh
File metadata and controls
116 lines (88 loc) · 1.76 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
113
114
115
116
##########################
## Basic Queries
##########################
#1
SELECT Name from students
#2
SELECT * from students where Age > 30
#3
SELECT Name from students where Age = 30 AND Gender = "F"
#4
SELECT Points from students where Name = "Alex"
#5
INSERT INTO students
VALUES (10, "Obaida", 25, "F", 100);
#6
UPDATE students
SET Points = Points + 100
WHERE Name = "Basma";
#7
UPDATE students
SET Points = Points - 100
WHERE Name = "Alex";
##########################
## Creating Table
##########################
#1
CREATE TABLE graduates (
ID INTEGER NOT NULL,
Name TEXT NOT NULL UNIQUE,
Age INTEGER,
Gender TEXT,
Points INTEGER,
Graduation TEXT,
PRIMARY KEY(ID AUTOINCREMENT)
);
#2
INSERT INTO graduates (Name,Age,Gender,Points)
SELECT Name,Age,Gender,Points
FROM students
WHERE name like "Layal";
#3
UPDATE graduates
SET Graduation = "2018-09-08"
WHERE Name like "Layal";
#4
DELETE FROM students
WHERE name like "Layal";
##########################
## Joins
##########################
#1
SELECT employees.Name, companies.Name, companies.Date
FROM employees
INNER JOIN companies ON employees.Company = companies.Name
#2
SELECT employees.Name
FROM employees
INNER JOIN companies ON employees.Company = companies.Name
WHERE companies.Date < 2000
#3
SELECT companies.Name
FROM companies
INNER JOIN employees ON employees.Company = companies.Name
WHERE employees.Role = "Graphic Designer"
##########################
## Count & Filter
##########################
#1
SELECT * , max(Points)
FROM students
#2
SELECT avg(Points)
FROM students
#3
SELECT count(ID)
FROM students
WHERE Points = 500
#4
SELECT Name
FROM students
WHERE Name like "%s%"
#5
SELECT *
FROM students
ORDER BY Points DESC
##########################
## End
##########################