-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise15.sql
More file actions
58 lines (46 loc) · 1.75 KB
/
Copy pathexercise15.sql
File metadata and controls
58 lines (46 loc) · 1.75 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
/*
Lesson 15 Exercises
Written on: January 8, 2025
*/
USE TrackIt;
SHOW TABLES;
-- Exercise 15.1: Recent Tasks (26 rows)
TABLE project; -- Name, (FK)ProjectId
TABLE task; -- TaskId, Title, (FK)ProjectId
SELECT p.Name AS ProjectName, MAX(t.TaskId) AS MaxTaskId, t.Title AS MaxTaskTitle
FROM project p
JOIN task t ON p.ProjectId = t.ProjectId
GROUP BY p.Name;
-- Exercise 15.2: Before Grumps (513 rows)
-- Generate a list of tasks whose due date is no or before the due date for the project named Grumps. (Use subquery)
TABLE project; -- (FK)ProjectId, Name = 'Grumps', DueDate = '2018-11-01'
TABLE task; -- Title, DueDate, (FK)ProjectId
SELECT t.title, t.DueDate
FROM task t
WHERE t.DueDate <=
(SELECT p.DueDate
FROM project p
WHERE p.Name = 'Grumps');
-- Exercise 15.3: Project Due Dates (543 rows)
-- Create a view that displays a list of all project names and due dates, the title of each task associated with each project, and the first name and last name of each work assigned to the tasks.
-- Assign the view any name that makes sense to you.
TABLE project; -- (FK)ProjectId, Name
TABLE task; -- (FK)ProjectId, (FK)WorkerId, DueDate, Title
TABLE worker; -- (FK)WorkerId, FirstName, LastName
CREATE VIEW ProjectDueDates
AS
SELECT
p.Name ProjectName,
t.DueDate,
t.Title,
w.FirstName,
w.LastName
FROM project p
JOIN task t ON p.projectId = t.projectId
JOIN worker w ON t.WorkerId = w.workerId;
SELECT Title FROM ProjectDueDates; -- Check if the view table is successfully created.
-- Exercise 15.4: The Work of Ealasaid Blinco (15 rows)
-- Use the view created in the previous exercise to generate a list of all tasks assigned to worker Ealasaid Blinco.
SELECT ProjectName
FROM ProjectDueDates
WHERE FirstName = 'Ealasaid' AND LastName = 'Blinco';