2
Hello, I have a problem making a sum in a query. Example and query results:
select DISTINCT t.ID, t.nomeuc as "Nome UC", 
    t.tipoturno as "Tipo Turno", a.num_presencas as "Número de Presenças"
from ei_sad_proj_gisem.v_aulas_semana a 
    join ei_sad_proj_gisem.v_turnos t on a.turno_ID = t.ID
where turno_ID in (
    select ID 
    from ei_sad_proj_gisem.v_turnos 
    where abrevuc = 'SAD' group by ID);
And I have an output of:
ID Nome UC Tipo Número de Presenças
   171 Sistemas de Apoio à Decisão                        PL                     13
   149 Sistemas de Apoio à Decisão                        PL                     16
   146 Sistemas de Apoio à Decisão                        PL                     17
   148 Sistemas de Apoio à Decisão                        PL                     14
   151 Sistemas de Apoio à Decisão                        T                      53
   171 Sistemas de Apoio à Decisão                        PL                     14
   151 Sistemas de Apoio à Decisão                        T                      46
   148 Sistemas de Apoio à Decisão                        PL                     16
30 rows selected. 
I want to add up the amount of presences, however when I add only the SUM() I have an error of ORA-00937: not a single group function
The code would be as follows:
select DISTINCT t.ID, t.nomeuc as "Nome UC", 
    t.tipoturno as "Tipo Turno", SUM(a.num_presencas) as "Número de Presenças"
from ei_sad_proj_gisem.v_aulas_semana a 
    join ei_sad_proj_gisem.v_turnos t on a.turno_ID = t.ID
where turno_ID in (
    select ID 
    from ei_sad_proj_gisem.v_turnos 
    where abrevuc = 'SAD' group by ID);
I removed @Jeffersonquesado, I also removed the ID that would not let add
– Rovann Linhalis
Thanks @Rovann! I will mark as reply when pass the 10 mins!
– João Silva