how to group an sql

Asked

Viewed 55 times

-2

I have an SQL that when run gives error. Someone could help me to perform the grouping of this SQL?

select i.ref, r.nome,n.qtde,sum(n.vlr_tot)
  from geitens as i
  inner join gerefer as r on r.cod = i.ref
  inner join gelannfs as n on n.item = i.cod
  inner join gecadnfs as c on c.doc = n.doc
  where c.serie = 'Z' and n.mes = :mes and n.ano = :ano
    and c.mes = :mes and c.ano = :ano group by i.ref order by i.ref
  • 1

    Tried to make GROUP BY i.ref, r.nome,n.qtde?

1 answer

-1

Good afternoon, pretty boy?

Try to group in a generic way, as I do in several cases here..

Example :

select i.ref, r.nome,n.qtde,sum(n.vlr_tot) 
from geitens as i 
inner join gerefer as r on r.cod = i.ref 
inner join gelannfs as n on n.item = i.cod 
inner join gecadnfs as c on c.doc = n.doc 
where c.serie = 'Z' 
and n.mes = :mes 
and n.ano = :ano 
and c.mes = :mes 
and c.ano = :ano 
group by 1,2,3,4
order by i.ref

Browser other questions tagged

You are not signed in. Login or sign up in order to post.