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
98 lines (78 loc) · 1.74 KB
/
answers.sh
File metadata and controls
98 lines (78 loc) · 1.74 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
# first answer
SELECT * FROM students;
# second answer
SELECT * FROM students
WHERE Age > 30;
# third answer
SELECT * FROM students
WHERE Gender = "F" AND Age > 30;
# answer four
SELECT Points FROM students
WHERE name = "Alex";
# answer five
INSERT INTO students(name , Age, Gender, Points)VALUES("Ahmad", 20, "M", 30000);
# answer six
UPDATE students
SET Points = Points + 10 WHERE name = "Basma";
# answer seven
UPDATE students
SET Points = Points - 10 WHERE name = "Alex";
CREATE TABLE kousa AS
SELECT employees.name , employees.Company , companies.date
FROM employees
INNER JOIN companies
ON employees.company = companies.name
SELECT * FROM kousa
WHERE date < 2000;
# create table
CREATE TABLE graduates (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255) NOT NULL UNIQUE,
age INT,
gender VARCHAR(255),
points INT,
grad DATE
);
# insert values
INSERT INTO graduates (name, age, gender, points)
SELECT name, age, gender, points
FROM students
WHERE name = 'Layal';
# update
UPDATE graduates
SET grad = '08-09-2018'
WHERE name = 'Layal';
# delete
DELETE FROM students
WHERE name = "Layal";
#creating a joint table
CREATE TABLE kousa AS
SELECT employees.name , employees.Company, companies.date
FROM employees
INNER JOIN companies
ON employees.company = companies.name
#select
SELECT name FROM kousa
WHERE date < 2000
#Selecting Role
SELECT Company FROM employees
WHERE Role = "Graphic Designer"
# Order Desc
SELECT * from students
ORDER BY points DESC
LIMIT 1 ;
# Select avg
SELECT AVG(points) AS averagepoints
FROM students;
# Counting points
SELECT COUNT() AS numstudents
FROM students
WHERE points = 500;
# Select
SELECT name
FROM students
WHERE name LIKE '%s%';
# order desc
SELECT
FROM students
ORDER BY points DESC;"