1
I need to perform a select, which bring the total number of students enrolled per class and company, only when it is company ('X' e 'Y')
add up 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 companies bring the total sums of them.
I perform this select
, through the period and the class, which can be one or more classes. However I do not know how to bring the total sum of companies ('X' e 'Y')
add up 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
Upshot:
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
When making a question, never abbreviate the words, here the understanding is paramount.
– novic
I don’t know much about SELECT, so a path in my view would be in PHP WHILE to perform the class validations, but I still can’t imagine how if something comes up I give you a touch.
– Cleverson