Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a db that in one column have 5 possible values: "Fechado", "Aberto", "Em Despiste", "Cancelado", "Resolvido".

And im trying to do a query that counts the values to a json file

var data = "SELECT COUNT (*) FROM graficos WHERE ESTADO='FECHADO'";

I've tried this and it gives me [{"":189}]. How can i get the count of the other values ?

I think that this is a simple question but i can't reach it...It is possible to have the count of the other values on the same query ?

share|improve this question
I'm not seasoned in this SE site. But this doesn't seem like a question for DBA's. More like a question for developers. Stackoverflow seems like a better fit. – Cruncher Aug 19 '14 at 15:37
up vote 6 down vote accepted

You can return a list and then resolve it in code, if you like.

FROM graficos 
WHERE ESTADO IS NOT NULL -- Discounting NULL values, if any

This will return a list of each distinct ESTADO value, and the number of rows containing that value in graficos table.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.