-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.sql
More file actions
53 lines (47 loc) · 1.01 KB
/
select.sql
File metadata and controls
53 lines (47 loc) · 1.01 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
SELECT
i.ID,
i.name,
i.salary,
w.age,
c.title,
c.credits
FROM
instructor i
JOIN teaches t ON i.ID = t.ID
JOIN course c ON t.course_id = c.course_id
JOIN workers w ON i.ID = w.ID;
WITH InstructorCourseInfo AS (
SELECT
i.ID,
i.name,
i.salary,
i.dept_name,
t.course_id,
t.sec_id,
c.title,
c.credits
FROM
instructor i
JOIN teaches t ON i.ID = t.ID
JOIN course c ON t.course_id = c.course_id
)
SELECT
ici.ID,
ici.instructor_name,
ici.instructor_salary,
ici.dept_name,
ici.course_id,
ici.course_title,
ici.credits,
w.salary,
w.age
FROM workers w
JOIN InstructorCourseInfo ici ON ici.ID = w.ID;
SELECT *
FROM course
ORDER BY course.course_id ASC;
INSERT INTO teaches (ID, name, department, age)
VALUES (101, 'Alice', 'CS', 20);
DELETE FROM teaches WHERE ID > 21;
SELECT ID FROM instructor AS c WHERE ID = 4;
SELECT ID AS id FROM instructor JOIN course ON instructor.ID = credits;