Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
grade
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Yushko
grade
Commits
df984568
Commit
df984568
authored
6 years ago
by
Anton Bagliy
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue391_extra_students' into develop
parents
5e31e7d9
c8a0c29e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
db/postgresql/issue391_extra_students.sql
+90
-0
90 additions, 0 deletions
db/postgresql/issue391_extra_students.sql
with
90 additions
and
0 deletions
db/postgresql/issue391_extra_students.sql
0 → 100644
+
90
−
0
View file @
df984568
DROP
FUNCTION
IF
EXISTS
public
.
getratesforgroupbystage
(
pdisciplineid
integer
,
pgroupid
integer
,
pmilestone
integer
);
CREATE
OR
REPLACE
FUNCTION
public
.
getratesforgroupbystage
(
pdisciplineid
integer
,
pgroupid
integer
,
pmilestone
integer
)
RETURNS
TABLE
(
"StudentID"
integer
,
"Semester"
integer
,
"Bonus"
integer
,
"Extra"
integer
,
"PreviousExtra"
integer
,
"Exam"
integer
,
"PreviousExam"
integer
,
"Option"
absence_pass
,
"AutoPassed"
integer
,
"LastName"
character
varying
,
"FirstName"
character
varying
,
"SecondName"
character
varying
)
LANGUAGE
plpgsql
AS
$
function
$
DECLARE
vSemesterID
INT
DEFAULT
-
1
;
vGroupID
INT
DEFAULT
-
1
;
vInGeneralGroup
BOOL
DEFAULT
FALSE
;
BEGIN
vSemesterID
:
=
GetDisciplineProperty
(
pDisciplineID
,
'semester'
);
/*DROP TABLE IF EXISTS tStudents;
CREATE TEMPORARY TABLE tStudents (
StudentID INT NOT NULL
);*/
-- check that group attached to discipline. Otherwise vGroupID = -1;
vInGeneralGroup
=
EXISTS
(
SELECT
*
FROM
disciplines_groups
WHERE
disciplines_groups
.
DisciplineID
=
pDisciplineID
AND
disciplines_groups
.
GroupID
=
pGroupID
LIMIT
1
);
/* DROP TABLE IF EXISTS tStudents;
CREATE TEMPORARY TABLE tStudents AS (
SELECT record_books.ID, record_books.StudentID
FROM students_groups
LEFT JOIN record_books ON record_books.ID = students_groups.RecordBookID
left JOIN disciplines_students ON disciplines_students.DisciplineID = pDisciplineID AND
disciplines_students.RecordBookID = record_books.ID
WHERE students_groups.SemesterID = vSemesterID AND
students_groups.State <= 'outlet' AND --actual students
students_groups.GroupID = pGroupID and
COALESCE(disciplines_students.Type, 'attach') = 'attach'
--CASE WHEN vInGeneralGroup THEN
-- NOT disciplines_students.Type <=> 'detach' # not detached
-- ELSE
-- COALESCE(disciplines_students.Type, 'attach') = 'attach' # is attached
-- END
);*/
DROP
TABLE
IF
EXISTS
tStudents
;
CREATE
TEMPORARY
TABLE
tStudents
AS
(
SELECT
record_books
.
ID
,
record_books
.
StudentID
FROM
students_groups
--left
JOIN
record_books
ON
record_books
.
ID
=
students_groups
.
RecordBookID
LEFT
JOIN
disciplines_students
on
disciplines_students
.
DisciplineID
=
pDisciplineid
and
disciplines_students
.
RecordBookID
=
record_books
.
ID
left
join
view_disciplines_recordbooks
on
students_groups
.
recordbookid
=
view_disciplines_recordbooks
.
recordbookid
WHERE
students_groups
.
SemesterID
=
vSemesterID
AND
students_groups
.
State
<=
'outlet'
AND
students_groups
.
GroupID
=
pgroupid
and
COALESCE
(
disciplines_students
.
Type
,
'attach'
)
=
'attach'
and
view_disciplines_recordbooks
.
disciplineid
=
pDisciplineid
);
return
query
SELECT
tRes
.
*
,
accounts
.
LastName
as
"LastName"
,
accounts
.
FirstName
as
"FirstName"
,
accounts
.
SecondName
as
"SecondName"
FROM
(
SELECT
tStudents
.
StudentID
as
"StudentID"
,
cast
(
SUM
(
tRate
.
Rate
*
iif_sql
(
tMap
.
ModuleType
=
'regular'
,
1
,
0
))
as
integer
)
AS
"Semester"
,
cast
(
SUM
(
tRate
.
Rate
*
iif_sql
(
tMap
.
ModuleType
=
'bonus'
,
1
,
0
))
as
integer
)
AS
"Bonus"
,
cast
(
SUM
(
tRate
.
Rate
*
iif_sql
(
tMap
.
ModuleType
=
'extra'
,
1
,
0
)
*
iif_sql
(
tMap
.
SubmoduleOrderNum
<
pMilestone
,
1
,
0
))
as
integer
)
AS
"Extra"
,
cast
(
SUM
(
tRate
.
Rate
*
iif_sql
(
tMap
.
ModuleType
=
'extra'
,
1
,
0
)
*
iif_sql
(
tMap
.
SubmoduleOrderNum
<
pMilestone
-
1
,
1
,
0
))
as
integer
)
AS
"PreviousExtra"
,
cast
(
SUM
(
tRate
.
Rate
*
iif_sql
(
tMap
.
ModuleType
=
'exam'
,
1
,
0
)
*
iif_sql
(
tMap
.
SubmoduleOrderNum
=
pMilestone
,
1
,
0
))
as
integer
)
AS
"Exam"
,
MAX
(
tRate
.
Rate
*
iif_sql
(
tMap
.
ModuleType
=
'exam'
,
1
,
0
)
*
iif_sql
(
tMap
.
SubmoduleOrderNum
<
pMilestone
,
1
,
0
))
AS
"PreviousExam"
,
MAX
(
CASE
WHEN
tMap
.
SubmoduleOrderNum
=
pMilestone
THEN
exam_period_options
.
"type"
ELSE
NULL
END
)
As
"Option"
,
MAX
(
CASE
WHEN
exam_period_options
.
"type"
=
'pass'
THEN
1
ELSE
0
END
)
As
"AutoPassed"
FROM
tStudents
LEFT
JOIN
view_roadmap
AS
tMap
ON
tMap
.
DisciplineID
=
pDisciplineID
LEFT
JOIN
rating_table
AS
tRate
ON
tRate
.
RecordbookID
=
tStudents
.
ID
AND
tRate
.
SubmoduleID
=
tMap
.
SubmoduleID
LEFT
JOIN
exam_period_options
ON
exam_period_options
.
submoduleID
=
tMap
.
SubmoduleID
AND
exam_period_options
.
RecordbookID
=
tStudents
.
ID
GROUP
BY
tStudents
.
StudentID
)
tRes
INNER
JOIN
students
ON
students
.
ID
=
tRes
.
"StudentID"
INNER
JOIN
accounts
ON
students
.
AccountID
=
accounts
.
ID
ORDER
BY
accounts
.
LastName
ASC
,
accounts
.
FirstName
ASC
,
accounts
.
SecondName
ASC
;
END
$
function
$
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment