2
I have 3 tables: inscricaoaluno
, inscricaoescola
and prova
, with the following structures:
PROOF
IDPROVA | DESCPROVA | TYPE | QTDEMAX
ENROLLED
TEACHER | SCHOOL(IDESCOLA) | DTINSCRICAO | IDPROVA
INSCRIBED
STUDENT(IDALUNO) | SCHOOL | DTINSCRICAO | IDPROVA
According to the tipo
of the test, 'COLLECTIVE' or 'INDIVIDUAL' I will get all enrolled schools and/or all enrolled students, for this I would like to make a query to get only the quantities...
Here’s what I’m trying to do:
select * from prova p
left join (
case when p.tipo='COLETIVO' then
(SELECT ie.idProva, count(ie.idEscola) as qtde FROM inscricaoescola ie
group by ie.idProva)
else
(SELECT ia.idProva, count(ia.idaluno) as qtde FROM inscricaoaluno ia
group by ia.idProva)
end as cont)
on cont.idprova = p.idprova;
In the Sqldeveloper console appears:
"parenthesis right not found"
I wonder if it is possible to create a Query with this structure that I tried to do /\
left join (case {condição} then {subquery} else {outra_subquery} )
If there aren’t any I’d like some light on how I can do that..
If I understand correctly, this information should be in the projection and not in JOIN, you want the total of schools or students that the test will have right?
– Caputo
In Sql Serve you can do using dynamic Querys. They are mounted as strings and then run.
– Marconi