How to bring two columns with different results

Asked

Viewed 394 times

0

I’m looking to put together a vision of the total projects Assets and Closed.

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

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

He returns me the total of active projects.

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

2 answers

1

Try it like this:

SELECT sum(ativo = 'S') as TotalAtivo,
sum(ativo = 'N') as TotalEncerrado
FROM projetos 
WHERE ativo in('S','N')

0


Usa group by for that reason:

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

How do you have two possible situations 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.

  • 1

    Thanks, solved!!

Browser other questions tagged

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