0% found this document useful (0 votes)
10 views7 pages

Assignment 1

Uploaded by

Mungara Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Assignment 1

Uploaded by

Mungara Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ASSIGNMENT 1

NAME:- TRUSHAL SANGANI

ANS 1

SELECT
c.Title AS Course_Name,
d.DepartmentID AS Department_Name, -- Assuming a mapping for department
names
CONCAT(ci_instructor.FirstName, ' ', ci_instructor.LastName) AS
Course_Instructor,
COUNT(DISTINCT sg.StudentID) AS Number_of_Students
FROM
course c
LEFT JOIN
studentgrade sg ON c.CourseID = sg.CourseID
LEFT JOIN
courseinstructor ci ON c.CourseID = ci.CourseID
LEFT JOIN
person ci_instructor ON ci.PersonID = ci_instructor.PersonID
LEFT JOIN
departments d ON c.DepartmentID = d.DepartmentID -- Assuming a `department`
table for department names
GROUP BY
c.CourseID, ci.PersonID;

OUTPUT
ANS 2

CREATE OR REPLACE VIEW StudentCourseGrades AS


SELECT
sg.EnrollmentID AS Enrollment_ID,
sg.StudentID AS Student_ID,
sg.CourseID AS Course_ID,
c.Title AS Course_Name,
c.Credits AS Course_Credits,
sg.Grade AS Student_Grade
FROM
studentgrade sg
JOIN
course c ON sg.CourseID = c.CourseID;

OUTPUT
ANS 3

CREATE OR REPLACE VIEW StudentCourseGrades AS


SELECT
sg.EnrollmentID AS Enrollment_ID,
sg.StudentID AS Student_ID,
p.FirstName AS Student_First_Name,
p.LastName AS Student_Last_Name,
sg.CourseID AS Course_ID,
c.Title AS Course_Name,
c.Credits AS Course_Credits,
sg.Grade AS Student_Grade
FROM
studentgrade sg
JOIN
course c ON sg.CourseID = c.CourseID
JOIN
person p ON sg.StudentID = p.PersonID;
OUTPUT

ANS 4

CREATE OR REPLACE VIEW StudentCourseGrades AS


SELECT
sg.EnrollmentID AS Enrollment_ID,
sg.StudentID AS Student_ID,
p.FirstName AS Student_First_Name,
p.LastName AS Student_Last_Name,
sg.CourseID AS Course_ID,
c.Title AS Course_Name,
c.Credits AS Course_Credits,
sg.Grade AS Student_Grade_Out_of_4,
(sg.Grade * 5) AS Student_Grade_Out_of_20
FROM
studentgrade sg
INNER JOIN
course c ON sg.CourseID = c.CourseID
INNER JOIN
person p ON sg.StudentID = p.PersonID;

OUTPUT
ANS 4

SELECT
sg.StudentID AS Student_ID,
p.FirstName AS Student_First_Name,
p.LastName AS Student_Last_Name,
(
SELECT
SUM((sg_sub.Grade * 5) * c.Credits)
FROM
studentgrade sg_sub
INNER JOIN
course c ON sg_sub.CourseID = c.CourseID
WHERE
sg_sub.StudentID = p.PersonID
)/
(
SELECT
SUM(c.Credits)
FROM
studentgrade sg_sub
INNER JOIN
course c ON sg_sub.CourseID = c.CourseID
WHERE
sg_sub.StudentID = p.PersonID
) AS Weighted_Average_Grade_Out_of_20
FROM
person p
INNER JOIN
studentgrade sg ON sg.StudentID = p.PersonID
WHERE
p.Discriminator = 'Student';

OUTPUT

ANS 5

SELECT
sg.StudentID AS Student_ID,
p.FirstName AS Student_First_Name,
p.LastName AS Student_Last_Name,
(
SELECT
SUM((sg_sub.Grade * 5) * c.Credits)
FROM
studentgrade sg_sub
INNER JOIN
course c ON sg_sub.CourseID = c.CourseID
WHERE
sg_sub.StudentID = p.PersonID
)/
(
SELECT
SUM(c.Credits)
FROM
studentgrade sg_sub
INNER JOIN
course c ON sg_sub.CourseID = c.CourseID
WHERE
sg_sub.StudentID = p.PersonID
) AS Weighted_Average_Grade_Out_of_20
FROM
person p
INNER JOIN
studentgrade sg ON sg.StudentID = p.PersonID
WHERE
p.Discriminator = 'Student'
ORDER BY
Weighted_Average_Grade_Out_of_20 DESC;

OUTPUT

You might also like