lundi 15 juin 2015

SQLITE3 return count based on column's value

Example of my table :

ID    MACHINE    RESULT
1     A            fail
2     A            pass
3     B            pass
4     A            fail

The next query gets the number of pass and fail from all the MACHINE

SELECT RESULT, COUNT(*) FROM my_table GROUP BY RESULT

The answer is :

2 fail 2 pass

My goal is to get the pass and fail count from a specific MACHINE . I tried the follow :

SELECT RESULT, COUNT(*) FROM my_table  WHERE MACHINE = 'A' GROUP BY RESULT

It doesnt work as expected . And I'm expecting :

2 fail 1 pass

Where is my mistake ? :<

Aucun commentaire:

Enregistrer un commentaire