patternMinor
Simple SQL Query
Viewed 0 times
sqlquerysimple
Problem
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
I've tried this and it gives me
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 ?
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 ?
Solution
You can return a list and then resolve it in code, if you like.
This will return a list of each distinct ESTADO value, and the number of rows containing that value in graficos table.
SELECT ESTADO, COUNT(*) CNT
FROM graficos
WHERE ESTADO IS NOT NULL -- Discounting NULL values, if any
GROUP BY ESTADOThis will return a list of each distinct ESTADO value, and the number of rows containing that value in graficos table.
Code Snippets
SELECT ESTADO, COUNT(*) CNT
FROM graficos
WHERE ESTADO IS NOT NULL -- Discounting NULL values, if any
GROUP BY ESTADOContext
StackExchange Database Administrators Q#74323, answer score: 5
Revisions (0)
No revisions yet.