Skip to content
Snippets Groups Projects
Commit f797b9f6 authored by PavelBegunkov's avatar PavelBegunkov
Browse files

Fix getRatesForGroup(ByStage) sp

parent ecc198bd
Branches
Tags
No related merge requests found
......@@ -1003,18 +1003,18 @@ BEGIN
SELECT students_groups.StudentID
FROM `students_groups`
LEFT JOIN `disciplines_students` ON disciplines_students.DisciplineID = pDisciplineID AND
disciplines_students.StudentID = students.ID
WHERE students_groups.StudentID = students.ID AND
students_groups.SemesterID = vSemesterID AND
students_groups.State <= 'outlet' AND
CASE WHEN !vInGeneralGroup THEN
students_groups.GroupID = pGroupID AND
disciplines_students.ID IS NOT NULL
disciplines_students.StudentID = students_groups.StudentID
WHERE students_groups.SemesterID = vSemesterID AND
students_groups.State <= 'outlet' AND # actual students
students_groups.GroupID = pGroupID AND
CASE WHEN vInGeneralGroup THEN
NOT disciplines_students.Type <=> 'detach' # not detached
ELSE
disciplines_students.ID IS NULL
disciplines_students.Type <=> 'attach' # is attached
END
);
DROP TABLE IF EXISTS vRoadMap
CREATE TEMPORARY TABLE vRoadMap AS (
SELECT view_roadmap.SubmoduleID,
view_roadmap.ModuleType AS 'Type'
......@@ -1037,8 +1037,8 @@ BEGIN
MAX(IF(vRoadMap.Type = 'exam', rt.Rate, 0)) AS 'RateExam'
FROM tStudents
CROSS JOIN vRoadMap
LEFT JOIN `rating_table` as rt ON rating_table.StudentID = tStudents.StudentID AND
rating_table.SubmoduleID = vRoadMap.SubmoduleID
LEFT JOIN `rating_table` as rt ON rt.StudentID = tStudents.StudentID AND
rt.SubmoduleID = vRoadMap.SubmoduleID
GROUP BY tStudents.StudentID
) vRates
INNER JOIN `students` ON students.ID = vRates.StudentID
......@@ -1126,6 +1126,7 @@ CREATE PROCEDURE `GetRatesForGroupByStage` (
) NO SQL
BEGIN
DECLARE vSemesterID, vGroupID INT DEFAULT -1;
DECLARE vInGeneralGroup BOOL DEFAULT FALSE;
SET vSemesterID = GetDisciplineProperty(pDisciplineID, 'semester');
DROP TABLE IF EXISTS tStudents;
CREATE TEMPORARY TABLE tStudents (
......@@ -1133,30 +1134,29 @@ BEGIN
);
# check that group attached to discipline. Otherwise vGroupID = -1;
SELECT disciplines_groups.GroupID INTO vGroupID
FROM `disciplines_groups`
WHERE disciplines_groups.GroupID = pGroupID AND
disciplines_groups.DisciplineID = pDisciplineID
LIMIT 1;
SET vInGeneralGroup = EXISTS(
SELECT * FROM `disciplines_groups`
WHERE disciplines_groups.DisciplineID = pDisciplineID AND
disciplines_groups.GroupID = pGroupID
LIMIT 1
);
# get all students from group, that take this discipline
IF vGroupID <= 0 THEN # doesn't attached
INSERT INTO tStudents (`StudentID`)
SELECT disciplines_students.StudentID
FROM `disciplines_students`
WHERE disciplines_students.DisciplineID = pDisciplineID AND
disciplines_students.Type = 'attach';
ELSE # attached group
INSERT INTO tStudents (`StudentID`)
SELECT students_groups.StudentID
FROM `students_groups`
LEFT JOIN `disciplines_students` ON disciplines_students.StudentID = students_groups.StudentID AND
disciplines_students.DisciplineID = pDisciplineID
WHERE students_groups.GroupID = vGroupID AND
students_groups.SemesterID = vSemesterID AND
students_groups.State <= 'outlet' AND
NOT disciplines_students.Type <=> 'detach'; # exclude detached students
END IF;
DROP TABLE IF EXISTS tStudents;
CREATE TEMPORARY TABLE tStudents AS (
SELECT students_groups.StudentID
FROM `students_groups`
LEFT JOIN `disciplines_students` ON disciplines_students.DisciplineID = pDisciplineID AND
disciplines_students.StudentID = students_groups.StudentID
WHERE students_groups.SemesterID = vSemesterID AND
students_groups.State <= 'outlet' AND # actual students
students_groups.GroupID = pGroupID AND
CASE WHEN vInGeneralGroup THEN
NOT disciplines_students.Type <=> 'detach' # not detached
ELSE
disciplines_students.Type <=> 'attach' # is attached
END
);
SELECT tRes.*,
students.LastName,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment