I need to perform a select, which swallows the total number of students enrolled per class and company, only when it is company ('X' e 'Y')
add the total amount of them, ('D' e 'F')
also add up the total amount of them, for company. 'P' bring total amount of students only from this company and the other company bring the sum total of them.
I make this select
, through the period and the class, which can be one or more classes. But I do not know how to bring the total sum of companies ('X' e 'Y')
to add the total amount of them, ('D' e 'F')
.
SELECT COUNT(*) AS 'quant_total', empresa, turma FROM 'alunos'
WHERE data_matricula >= '2014-01-01' AND data_matricula <= '2014-02-01'
AND substr(turma, 1,4) IN ('AAAA') AND situacao = 'AT'
GROUP BY empresa, turma
Result:
quant_total |empresa |turma
1 | X | AAA
4 | X | BBB
4 | X | CCC
3 | X | DDD
1 | F | AAA
16 | D | AAA
33 | D | HHH
28 | D | XXX
18 | D | DDD
12 | P | AAA
1 | P | HHH
11 | P | BBB
14 | P | CCC
23 | P | ZZZ
1 | P | KKK
3 | Y | AAA
5 | Y | BBB
4 | Y | CCC
5 | Y | DDD
1 | O | BBB