Select Same Field

Asked

Viewed 32 times

0

Hello! I need to make an SQL that gives me the result and I wish in the same line. Today SQL is skipping a line. I need you to stay on the same line.

select c.empresa, p.nome, (select count(sequencialOC) where OrdemAut = 'N') as 'Com cotação', (select count(sequencialOC) where OrdemAut = 'S') as 'Sem cotação' from compras c inner join pessoas p on (c.empresa = p.codigo) where c.data between '01/01/2020' and '29/09/2020' group by c.OrdemAut,c.Empresa, c.nome

inserir a descrição da imagem aqui

  • Try to explain what result you want to achieve and also with these subselects which I consider to be meaningless.

  • The idea is to know which are the PURCHASE ORDER of a company that has a quotation and which purchase order does not have a quotation. I only wish to total the amount of each situation, filtering by company and by date.

1 answer

2

If I can understand what you want maybe:

select c.empresa, p.nome, SUM(CASE WHEN OrdemAut = 'N' THEN 1 ELSE 0 END) as 'Com cotação', SUM(CASE WHEN OrdemAut = 'S' THEN 1 ELSE 0 END) as 'Sem cotação' 
from compras c inner join pessoas p on (c.empresa = p.codigo) 
where c.data between '01/01/2020' and '29/09/2020' 
group by c.Empresa, c.nome

can serve you.

Browser other questions tagged

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