Click here to Skip to main content
15,040,743 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For example :
SQL
id   columnA

1    black
2    red
3    red
4    green
5    red
6    black
7    white 

I want to count total of "black" and "red" items. Result should be "5".

This code work fine, but if I try to add "red" it's not working.
Java
long count = DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM mytable WHERE columnA = '" + "black" + "', null);


Sorry my bad English, thanks for helping...

What I have tried:

long count = DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM mytable WHERE columnA = ('" + "black" + "' AND '" + "red" + "'"), null);
Posted
Updated 11-Jul-16 18:27pm
v3

SELECT somecolumn,someothercolumn, COUNT(*)
FROM my_table
GROUP BY somecolumn,someothercolumn


SQLite: count Function[^]
   
v2
Comments
bugsoul 11-Jul-16 9:10am
   
Thanks but I didn't ask this. I want to count 2 different items in only one column.
SQL
select type, count(type) from table group by type;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900