-
Notifications
You must be signed in to change notification settings - Fork 2
/
SQL003.sql
194 lines (181 loc) · 6.22 KB
/
SQL003.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
PLT09 - Script para cubo do ENAD
Create By Bitts (31/07/2015)
Obs.: Iniciado por Marcelo Fumaco e Terminado por Bitts
*/
SELECT
A.RA,
G.CODPESSOA,
UPPER(H.NOME) AS NOME,
I.NOME AS CURSO,
B.CODGRADE AS MATRIZ_CURRICULAR,
ELETIVAS.CHT_ELETIVA,
SUM(F.CH) AS CH_ELETIVAS,
CONVERT(VARCHAR, CEILING((CASE WHEN SUM(F.CH) > ELETIVAS.CHT_ELETIVA THEN ELETIVAS.CHT_ELETIVA ELSE SUM(F.CH) END) * 100 / ELETIVAS.CHT_ELETIVA )) +'%' AS PRC_ELETIVAS,
SOPTATIVAS.CHT_OPTATIVAS,
ISNULL (OPTATIVAS.CHTOTAL,0) AS CH_OPTATIVAS,
CONVERT(VARCHAR, CEILING((CASE WHEN ISNULL (OPTATIVAS.CHTOTAL,0) > SOPTATIVAS.CHT_OPTATIVAS THEN SOPTATIVAS.CHT_OPTATIVAS ELSE ISNULL (OPTATIVAS.CHTOTAL,0) END) * 100 / SOPTATIVAS.CHT_OPTATIVAS))+'%' AS PERC_OPTATIVAS,
K.VALORMINIMO AS CHT_ATV_COMPLEMENTARES,
ISNULL (SATIVCOMP.CARGH, 0) AS CH_ATV_COMPLEMENTARES,
CONVERT(VARCHAR, CEILING((CASE WHEN ISNULL (SATIVCOMP.CARGH, 0) > K.VALORMINIMO THEN K.VALORMINIMO ELSE ISNULL (SATIVCOMP.CARGH, 0) END) * 100 / K.VALORMINIMO))+'%' AS PRC_ATV_COMPLEMENTARES,
(ELETIVAS.CHT_ELETIVA + SOPTATIVAS.CHT_OPTATIVAS + K.VALORMINIMO) AS CHT_TOTAL,
(CASE WHEN SUM(F.CH) > ELETIVAS.CHT_ELETIVA THEN ELETIVAS.CHT_ELETIVA ELSE SUM(F.CH) END) +
(CASE WHEN ISNULL (OPTATIVAS.CHTOTAL,0) > SOPTATIVAS.CHT_OPTATIVAS THEN SOPTATIVAS.CHT_OPTATIVAS ELSE ISNULL (OPTATIVAS.CHTOTAL,0) END) +
(CASE WHEN ISNULL (SATIVCOMP.CARGH, 0) > K.VALORMINIMO THEN K.VALORMINIMO ELSE ISNULL (SATIVCOMP.CARGH, 0) END) AS CH_TOTAL
,
CONVERT(VARCHAR, CEILING(
(
(CASE WHEN SUM(F.CH) > ELETIVAS.CHT_ELETIVA THEN ELETIVAS.CHT_ELETIVA ELSE SUM(F.CH) END) +
(CASE WHEN ISNULL (OPTATIVAS.CHTOTAL,0) > SOPTATIVAS.CHT_OPTATIVAS THEN SOPTATIVAS.CHT_OPTATIVAS ELSE ISNULL (OPTATIVAS.CHTOTAL,0) END) +
(CASE WHEN ISNULL (SATIVCOMP.CARGH, 0) > K.VALORMINIMO THEN K.VALORMINIMO ELSE ISNULL (SATIVCOMP.CARGH, 0) END)
) * 100 / (ELETIVAS.CHT_ELETIVA + SOPTATIVAS.CHT_OPTATIVAS + K.VALORMINIMO)
))+'%' AS PRC_TOTAL,
DISC_TOTAL.TOTAL_DISCIPLINAS AS TOTL_DISCIPLINAS,
ISNULL( DISC_REST.TOTAL_RESTANTES, 0) AS REST_DISCIPLINAS,
CONVERT(VARCHAR, CEILING(( ISNULL(DISC_REST.TOTAL_RESTANTES,0) * 100) / DISC_TOTAL.TOTAL_DISCIPLINAS ))+'%' AS PERC_DISCIPLINAS
FROM
SHABILITACAOALUNO A(NOLOCK)
LEFT JOIN (
SELECT
RA, SUM (CARGAHORARIAATV) AS ATIVIDADES
FROM
SATIVIDADEALUNO (NOLOCK)
GROUP BY RA
) SATIVCOMP (RA, CARGH) ON SATIVCOMP.RA = A.RA
LEFT JOIN (
SELECT
A.RA, SUM(F.CH) AS CHTOTAL
FROM
SHABILITACAOALUNO A(NOLOCK),
SHABILITACAOFILIAL B(NOLOCK),
SGRADE C(NOLOCK),
SPERIODO D(NOLOCK),
SDISCGRADE E(NOLOCK)
LEFT JOIN
SHISTDISCOPTELETIVAS F(NOLOCK) ON F.STATUS = 'Aprovado'
WHERE
A.CODCOLIGADA = '3' AND
A.CODCOLIGADA = B.CODCOLIGADA AND
A.IDHABILITACAOFILIAL = B.IDHABILITACAOFILIAL AND
B.CODCOLIGADA = C.CODCOLIGADA AND
B.CODCURSO = C.CODCURSO AND
B.CODHABILITACAO = C.CODHABILITACAO AND
B.CODGRADE = C.CODGRADE AND
C.CODCOLIGADA = D.CODCOLIGADA AND
C.CODCURSO = D.CODCURSO AND
C.CODHABILITACAO = D.CODHABILITACAO AND
C.CODGRADE = D.CODGRADE AND
D.CODCOLIGADA = E.CODCOLIGADA AND
D.CODCURSO = E.CODCURSO AND
D.CODHABILITACAO = E.CODHABILITACAO AND
D.CODGRADE = E.CODGRADE AND
D.CODPERIODO = E.CODPERIODO AND
E.TIPODISC IN ('O','E') AND
A.CODCOLIGADA = F.CODCOLIGADA AND
A.RA = F.RA AND
E.CODDISC = F.CODDISC AND
A.IDHABILITACAOFILIAL = F.IDHABILITACAOFILIAL
GROUP BY
A.RA, F.STATUS
) OPTATIVAS (RA, CHTOTAL) ON OPTATIVAS.RA = A.RA
LEFT JOIN (
SELECT
C.RA, COUNT(B.CODDISC) AS DISCIPLINAS_RESTANTES
FROM
SDISCGRADE A (NOLOCK)
LEFT JOIN SDISCIPLINA B (NOLOCK) ON A.CODDISC = B.CODDISC,
SHABILITACAOALUNO C (NOLOCK)
LEFT JOIN SHABILITACAOFILIAL D (NOLOCK) ON C.IDHABILITACAOFILIAL = D.IDHABILITACAOFILIAL
WHERE
A.TIPODISC = 'B' AND
A.CODGRADE = D.CODGRADE AND
B.CODDISC NOT IN (SELECT CODDISC FROM SHISTDISCCONCLUIDAS WHERE RA=C.RA)
GROUP BY
C.RA
) DISC_REST (RA, TOTAL_RESTANTES) ON DISC_REST.RA = A.RA
LEFT JOIN (
SELECT
C.RA, COUNT(B.CODDISC) AS TOTAL_DISCIPLINAS
FROM
SDISCGRADE A (NOLOCK)
LEFT JOIN SDISCIPLINA B (NOLOCK) ON A.CODDISC = B.CODDISC,
SHABILITACAOALUNO C (NOLOCK)
LEFT JOIN SHABILITACAOFILIAL D (NOLOCK) ON C.IDHABILITACAOFILIAL = D.IDHABILITACAOFILIAL
WHERE
A.TIPODISC = 'B' AND
A.CODGRADE = D.CODGRADE
GROUP BY
C.RA
) DISC_TOTAL (RA, TOTAL_DISCIPLINAS) ON DISC_TOTAL.RA = A.RA
,
SHABILITACAOFILIAL B(NOLOCK)
LEFT JOIN (
SELECT
SG.CODGRADE, SUM(SD.CH) AS TOTAL_CH_ELETIVA
FROM
SDISCGRADE SG (NOLOCK)
LEFT JOIN SDISCIPLINA SD (NOLOCK) ON SG.CODDISC=SD.CODDISC
WHERE
SG.TIPODISC = 'B'
GROUP BY
SG.CODCURSO, SG.CODGRADE, SG.TIPODISC
) ELETIVAS ( CODGRADE, CHT_ELETIVA ) ON ELETIVAS.CODGRADE=B.CODGRADE
LEFT JOIN (
SELECT
SUM(VALOROPTATIVA) AS CHT_OPTATIVAS, CODGRADE
FROM
SPERIODO (NOLOCK)
GROUP BY
CODCURSO, CODGRADE
) SOPTATIVAS (CHT_OPTATIVAS, CODGRADE) ON SOPTATIVAS.CODGRADE = B.CODGRADE
,
SGRADE C(NOLOCK),
SPERIODO D(NOLOCK),
SDISCGRADE E(NOLOCK),
SHISTDISCCONCLUIDAS F(NOLOCK),
SALUNO G(NOLOCK),
PPESSOA H (NOLOCK),
SCURSO I(NOLOCK),
SCOMPONENTECURRICULAR K (NOLOCK),
SCOMPONENTE L (NOLOCK)
WHERE
A.CODCOLIGADA = '3' AND
A.CODCOLIGADA = B.CODCOLIGADA AND
A.IDHABILITACAOFILIAL = B.IDHABILITACAOFILIAL AND
B.CODCOLIGADA = C.CODCOLIGADA AND
B.CODCURSO = C.CODCURSO AND
B.CODHABILITACAO = C.CODHABILITACAO AND
B.CODGRADE = C.CODGRADE AND
C.CODCOLIGADA = D.CODCOLIGADA AND
C.CODCURSO = D.CODCURSO AND
C.CODHABILITACAO = D.CODHABILITACAO AND
C.CODGRADE = D.CODGRADE AND
D.CODCOLIGADA = E.CODCOLIGADA AND
D.CODCURSO = E.CODCURSO AND
D.CODHABILITACAO = E.CODHABILITACAO AND
D.CODGRADE = E.CODGRADE AND
D.CODPERIODO = E.CODPERIODO AND
E.TIPODISC IN ('B','E') AND
A.CODCOLIGADA = F.CODCOLIGADA AND
A.RA = F.RA AND
E.CODDISC = F.CODDISC AND
A.IDHABILITACAOFILIAL = F.IDHABILITACAOFILIAL AND
G.RA = A.RA AND
G.CODPESSOA = H.CODIGO AND
B.CODCURSO = I.CODCURSO AND
K.CODCOMPONENTE=L.CODCOMPONENTE AND
B.IDHABILITACAOFILIAL=K.IDHABILITACAOFILIAL
GROUP BY
A.RA,
H.NOME,
G.RA,
OPTATIVAS.CHTOTAL,
G.CODPESSOA,
I.NOME,
SATIVCOMP.CARGH,
ELETIVAS.CHT_ELETIVA,
B.CODGRADE,
K.VALORMINIMO,
SOPTATIVAS.CHT_OPTATIVAS,
DISC_REST.TOTAL_RESTANTES,
DISC_TOTAL.TOTAL_DISCIPLINAS