Add counter - Postgresql

Asked

Viewed 119 times

0

I have the following Query:

SELECT 
array_to_string(array_agg('"'||public.lotesretornosuprimento.codigoestoque||'"'), ', ') as codigos,
est.codigosuprimento, 
public.suprimento.suprimento,
(
    select count(est02.codigosuprimento) from public.estoque est02 where est02.numeronotafiscal = est.numeronotafiscal and
    est.codigosuprimento = est02.codigosuprimento

) as qtdSuprimento, 
est.codigofornecedor,  
public.fornecedor.nome,
est.numeronotafiscal, 
to_char(est.datanotafiscal, 'dd/MM/yyyy') as datanotafiscal
FROM 
public.estoque est,
public.suprimento,
public.fornecedor,
public.lotesretornosuprimento
where 
public.lotesretornosuprimento.dataretorno between '2018-01-01' and '2019-01-24' and
est.codigosuprimento = public.suprimento.codigo and
est.codigosuprimento between 155 and 155 and
est.codigofornecedor = public.fornecedor.codigo and
est.codigofornecedor between 8 and 8 and
public.lotesretornosuprimento.codigoestoque = est.codigo 
group by 
est.codigosuprimento, 
est.codigofornecedor, 
est.numeronotafiscal, 
est.datanotafiscal,
public.suprimento.suprimento,
public.fornecedor.nome 
order by
public.fornecedor.nome,
public.suprimento.suprimento,
est.numeronotafiscal

That among N items that are returned to me are a counter that shows me the amount of a certain supply within a note, which is that part of the Query:

    (select count(est02.codigosuprimento) from public.estoque est02 where est02.numeronotafiscal = est.numeronotafiscal and
est.codigosuprimento = est02.codigosuprimento) as qtdSuprimento

I need to add this counter, how could I accomplish this?

My return is so at the moment:

inserir a descrição da imagem aqui

  • I could provide a simple example of how the current result of your query is and how you would like it to be, because I’m not sure I fully understood that part of adding up the Count result.

  • @Spockwayne updated my question to show my return like this so far

No answers

Browser other questions tagged

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