Add new changes

This commit is contained in:
Win 2025-09-15 20:12:55 +07:00
parent c6a63e11ef
commit 8accc5e309
15 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,49 @@
# SEN-209: Lab 3 - ERD & SQL CRUD
## Insert 3 students and 2 courses
INSERT INTO students VALUES
(1000, 'Peter', 'Parker', '2001-08-10'),
(1001, 'Miles', 'Morales', '2001-08-03'),
(1002, 'Gwen', 'Stacy', '2001-04-18');
INSERT INTO courses VALUES
('2sf3Lf', 'Physics I', 5),
('XjxDA6', 'Chemistry I', 6),
('3lScza', 'Biology I', 4);
## Enroll students into courses with grades
INSERT INTO enrollment VALUES
(1000, 'XjxDA6', 'A'),
(1000, '3lScza', 'A+'),
(1001, '2sf3Lf', 'B'),
(1002, 'XjxDA6', 'A'),
(1002, '2sf3Lf', 'A+');
## Retrieve all students with their enrolled courses
SELECT
st.fname,
st.lname,
STRING_AGG
(
c.cName, ','
) enrolled
FROM students st
INNER JOIN enrollment e ON e.sID = st.sID
INNER JOIN courses c ON c.cID = e.cID
GROUP BY st.fname, st.lname;
## Update one student's grade
UPDATE enrollment
SET grade = 'A'
WHERE
sID = 1001
AND
cID = '2sf3Lf';
## Delete one enrollment record
DELETE FROM enrollment
WHERE
sID = 1002
AND
cID = 'XjxDA6';

View File

@ -0,0 +1,48 @@
# SEN-209: Lab 3 - ERD & SQL CRUD
## Insert 3 students and 2 courses
INSERT INTO students VALUES
(1000, 'Peter', 'Parker', '2001-08-10'),
(1001, 'Miles', 'Morales', '2001-08-03'),
(1002, 'Gwen', 'Stacy', '2001-04-18');
INSERT INTO courses VALUES
('2sf3Lf', 'Physics I', 5),
('XjxDA6', 'Chemistry I', 6),
## Enroll students into courses with grades
INSERT INTO enrollment VALUES
(1000, 'XjxDA6', 'A'),
(1000, '2sf3Lf', 'A+'),
(1001, '2sf3Lf', 'B'),
(1002, 'XjxDA6', 'A'),
(1002, '2sf3Lf', 'A+');
## Retrieve all students with their enrolled courses
SELECT
st.fname,
st.lname,
STRING_AGG
(
c.cName, ','
) enrolled
FROM students st
INNER JOIN enrollment e ON e.sID = st.sID
INNER JOIN courses c ON c.cID = e.cID
GROUP BY st.fname, st.lname;
## Update one student's grade
UPDATE enrollment
SET grade = 'A'
WHERE
sID = 1001
AND
cID = '2sf3Lf';
## Delete one enrollment record
DELETE FROM enrollment
WHERE
sID = 1002
AND
cID = 'XjxDA6';

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB