How to bring two columns with different results

0

I want to put together a view of the total Assets and Closed projects.

I have a projetos table with the fields nome , descricao , ativo (can be S or N)

SELECT COUNT(*) as Total FROM projetos WHERE ativo = 'S'

It returns me the total of active projects.

Is there any way to bring the total of active and closed projects into the same query?

    
asked by anonymous 09.08.2017 / 19:09

2 answers

0

Use group by for this:

SELECT ativo as 'Situacao', COUNT(*) as 'Total' FROM projetos GROUP BY ativo

As you have two possible situations for ativo ('S' and 'N'), it will return the total of those that are 'S' on one line and those that are 'N' on the other.     

09.08.2017 / 19:11
1

Try this:

SELECT sum(ativo = 'S') as TotalAtivo,
sum(ativo = 'N') as TotalEncerrado
FROM projetos 
WHERE ativo in('S','N')
    
09.08.2017 / 19:13