Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- update data with case case condition
UPDATE Student
SET graduation_date = CASE
WHEN e.semester = 'FALL' THEN '2024-12-15'
WHEN e.semester = 'SPRING' THEN '2024-06-15'
ELSE NULL
END
FROM Student AS s
JOIN Exam AS e ON s.id = e.student_id;


-- display outpt for SPRING semester
SELECT * FROM Student AS s
JOIN Exam AS e ON e.student_id = s.id
WHERE e.semester = 'SPRING'
LIMIT 10;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- display top 10 rows of the Student table
SELECT * FROM Student
LIMIT 10;

-- display top 10 result from a join of Exam
-- and Student table
SELECT * FROM Exam
JOIN Student ON Exam.student_id = Student.id
LIMIT 10;


-- UPDATE JOIN with WHERE clause
UPDATE Exam
SET e.grade = 'C'
FROM Exam AS e
JOIN Student AS s ON e.student_id = s.id
WHERE s.national_id = 123345566 AND e.grade IS NULL;


-- confirm the output
SELECT * FROM Exam AS e
JOIN Student AS s ON e.student_id = s.id
WHERE national_id = 123345566;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--analyze query performance after assigning composite index
EXPLAIN SELECT *
FROM Student
WHERE enrollment_date = '2020-01-15' AND gpa > 4.0;

--optimized query
SELECT *
FROM Student
WHERE enrollment_date = '2020-01-15' AND gpa > 4.0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--analyze query performance on column without composite index assigned, using EXPLAIN
EXPLAIN SELECT *
FROM Student
WHERE birth_date = '2002-05-15' AND gpa > 3.5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--show index in table
SHOW INDEX FROM Student;

--create index on multiple columns
CREATE INDEX idx_enrollment_gpa
ON Student (enrollment_date, gpa);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--drop the index created
DROP INDEX idx_enrollment_gpa
ON Student;

--Verify if index is dropped
SHOW INDEX FROM Student;