SELECT JSON_OBJECT(
'username' VALUE TRIM(username),
'firstName' VALUE TRIM(firstName),
'lastName' VALUE TRIM(lastName),
'roomNo' VALUE TRIM(roomNo),
'facultyCode' VALUE TRIM(facultyCode)
FROM Faculty
ORDER BY TRIM(username) ASC;
/****** Students Collections ******/
SELECT JSON_OBJECT(
'username' VALUE TRIM(CSEStudent.username),
'firstName' VALUE TRIM(CSEStudent.firstName),
'lastName' VALUE TRIM(CSEStudent.lastName),
'groupId' VALUE CASE
WHEN MAX(CSEStudent.groupId) IS NOT NULL OR
MAX(TRIM(ProjectGroup.groupCode)) IS NOT NULL THEN
MAX(CSEStudent.groupId)
ELSE NULL
END,
'groupCode' VALUE CASE
WHEN MAX(CSEStudent.groupId) IS NOT NULL OR
MAX(TRIM(ProjectGroup.groupCode)) IS NOT NULL THEN
MAX(TRIM(ProjectGroup.groupCode))
ELSE NULL
END,
'assignedFypId' VALUE ProjectGroup.assignedFypId,
'reader' VALUE TRIM(ProjectGroup.reader),
'supervisorGrades' VALUE CASE
WHEN MAX(SRG.proposalReport) IS NOT NULL OR
MAX(SRG.progressReport) IS NOT NULL OR
MAX(SRG.finalReport) IS NOT NULL OR MAX(SRG.presentation) IS
NOT NULL THEN
JSON_ARRAY(
CASE WHEN MAX(SRG.proposalReport) IS NOT NULL THEN
JSON_OBJECT('proposalReport' VALUE MAX(SRG.proposalReport)) END,
CASE WHEN MAX(SRG.progressReport) IS NOT NULL THEN
JSON_OBJECT('progressReport' VALUE MAX(SRG.progressReport)) END,
CASE WHEN MAX(SRG.finalReport) IS NOT NULL THEN
JSON_OBJECT('finalReport' VALUE MAX(SRG.finalReport)) END,
CASE WHEN MAX(SRG.presentation) IS NOT NULL THEN
JSON_OBJECT('presentation' VALUE MAX(SRG.presentation)) END
ELSE NULL
END,
'readerGrades' VALUE CASE
WHEN MAX(RRG.proposalReport) IS NOT NULL OR
MAX(RRG.progressReport) IS NOT NULL OR
MAX(RRG.finalReport) IS NOT NULL OR MAX(RRG.presentation) IS
NOT NULL THEN
JSON_ARRAY(
CASE WHEN MAX(RRG.proposalReport) IS NOT NULL THEN
JSON_OBJECT('proposalReport' VALUE MAX(RRG.proposalReport)) END,
CASE WHEN MAX(RRG.progressReport) IS NOT NULL THEN
JSON_OBJECT('progressReport' VALUE MAX(RRG.progressReport)) END,
CASE WHEN MAX(RRG.finalReport) IS NOT NULL THEN
JSON_OBJECT('finalReport' VALUE MAX(RRG.finalReport)) END,
CASE WHEN MAX(RRG.presentation) IS NOT NULL THEN
JSON_OBJECT('presentation' VALUE MAX(RRG.presentation)) END
ELSE NULL
END
ABSENT ON NULL
FROM CSEStudent
LEFT OUTER JOIN ProjectGroup ON CSEStudent.groupId =
ProjectGroup.groupId
LEFT OUTER JOIN Supervises ON ProjectGroup.assignedFypId =
Supervises.fypId
LEFT OUTER JOIN RequirementGrades SRG ON (SRG.facultyUsername =
Supervises.username) AND (SRG.studentUsername =
CSEStudent.username)
LEFT OUTER JOIN RequirementGrades RRG ON (RRG.facultyUsername =
ProjectGroup.reader) AND (RRG.studentUsername =
CSEStudent.username)
GROUP BY
TRIM(CSEStudent.username), TRIM(CSEStudent.firstName),
TRIM(CSEStudent.lastName), CSEStudent.groupId,
TRIM(ProjectGroup.groupCode), ProjectGroup.assignedFypId,
TRIM(ProjectGroup.reader)
ORDER BY CSEStudent.groupId ASC, TRIM(CSEStudent.username) ASC;
----------------------------------------------------------------------
WITH StudentInfo AS (
SELECT
TRIM(CSEStudent.username) AS username,
TRIM(CSEStudent.firstName) AS firstName,
TRIM(CSEStudent.lastName) AS lastName,
CASE
WHEN TRIM(CSEStudent.groupId) is null OR
TRIM(ProjectGroup.groupCode) is null THEN null
ELSE CSEStudent.groupId
END AS groupId,
CASE
WHEN TRIM(CSEStudent.groupId) is null OR
TRIM(ProjectGroup.groupCode) is null THEN null
ELSE TRIM(ProjectGroup.groupCode)
END AS groupCode,
ProjectGroup.assignedFypId AS assignedFypId,
TRIM(ProjectGroup.reader) AS reader,
SRG.proposalReport,
SRG.progressReport,
SRG.finalReport,
SRG.presentation,
RRG.proposalReport AS rrg_proposalReport,
RRG.progressReport AS rrg_progressReport,
RRG.finalReport AS rrg_finalReport,
RRG.presentation AS rrg_presentation
FROM
CSEStudent
LEFT OUTER JOIN ProjectGroup ON CSEStudent.groupId =
ProjectGroup.groupId
LEFT OUTER JOIN Supervises ON ProjectGroup.assignedFypId =
Supervises.fypId
LEFT OUTER JOIN RequirementGrades SRG ON (SRG.facultyUsername =
Supervises.username) AND (SRG.studentUsername =
CSEStudent.username)
LEFT OUTER JOIN RequirementGrades RRG ON (RRG.facultyUsername =
ProjectGroup.reader) AND (RRG.studentUsername =
CSEStudent.username)
SELECT JSON_OBJECT(
'username' VALUE username,
'firstName' VALUE firstName,
'lastName' VALUE lastName,
'groupId' VALUE groupId,
'groupCode' VALUE groupCode,
'assignedFypId' VALUE assignedFypId,
'reader' VALUE reader,
'supervisorGrades' VALUE CASE
WHEN MAX(proposalReport) IS NOT NULL OR MAX(progressReport) IS
NOT NULL OR
MAX(finalReport) IS NOT NULL OR MAX(presentation) IS NOT NULL
THEN
JSON_ARRAY(
CASE WHEN MAX(proposalReport) IS NOT NULL THEN
JSON_OBJECT('proposalReport' VALUE MAX(proposalReport)) END,
CASE WHEN MAX(progressReport) IS NOT NULL THEN
JSON_OBJECT('progressReport' VALUE MAX(progressReport)) END,
CASE WHEN MAX(finalReport) IS NOT NULL THEN
JSON_OBJECT('finalReport' VALUE MAX(finalReport)) END,
CASE WHEN MAX(presentation) IS NOT NULL THEN
JSON_OBJECT('presentation' VALUE MAX(presentation)) END
ELSE NULL
END,
'readerGrades' VALUE CASE
WHEN MAX(rrg_proposalReport) IS NOT NULL OR
MAX(rrg_progressReport) IS NOT NULL OR
MAX(rrg_finalReport) IS NOT NULL OR MAX(rrg_presentation) IS
NOT NULL THEN
JSON_ARRAY(
CASE WHEN MAX(rrg_proposalReport) IS NOT NULL THEN
JSON_OBJECT('proposalReport' VALUE MAX(rrg_proposalReport)) END,
CASE WHEN MAX(rrg_progressReport) IS NOT NULL THEN
JSON_OBJECT('progressReport' VALUE MAX(rrg_progressReport)) END,
CASE WHEN MAX(rrg_finalReport) IS NOT NULL THEN
JSON_OBJECT('finalReport' VALUE MAX(rrg_finalReport)) END,
CASE WHEN MAX(rrg_presentation) IS NOT NULL THEN
JSON_OBJECT('presentation' VALUE MAX(rrg_presentation)) END
ELSE NULL
END
ABSENT ON NULL
FROM StudentInfo
GROUP BY
username, firstName, lastName, groupId, groupCode, assignedFypId,
reader
ORDER BY groupId ASC, username ASC;
/****** FYPs Collections ******/
SELECT JSON_OBJECT(
'fypId' VALUE FYP.fypId,
'title' VALUE TRIM(FYP.title),
'description' VALUE TRIM(FYP.description),
'category' VALUE TRIM(FYP.category),
'type' VALUE TRIM(FYP.type),
'otherRequirements' VALUE TRIM(FYP.otherRequirements),
'minStudents' VALUE FYP.minStudents,
'maxStudents' VALUE FYP.maxStudents,
'status' VALUE TRIM(FYP.status),
'supervisors' VALUE (
SELECT JSON_ARRAYAGG(username)
FROM (
SELECT TRIM(Supervises.username) as username
FROM Supervises
WHERE Supervises.fypId = FYP.fypId
),
'interestedGroups' VALUE (
SELECT JSON_ARRAYAGG(
JSON_OBJECT('groupId' VALUE InterestedIn.groupId, 'priority' VALUE
InterestedIn.priority)
FROM InterestedIn
WHERE InterestedIn.fypId = FYP.fypId
absent on null
FROM FYP
LEFT OUTER JOIN InterestedIn ON InterestedIn.fypId = FYP.fypId
GROUP BY FYP.fypId, TRIM(FYP.title), TRIM(FYP.description),
TRIM(FYP.category), TRIM(FYP.type),
TRIM(FYP.otherRequirements), FYP.minStudents, FYP.maxStudents,
TRIM(FYP.status)
ORDER BY FYP.fypId ASC;