在sqlite中计算一个列中的多项? [英] Count muttiple items in the sqlite a column ?
问题描述
例如:
id columnA
1 black
2 red
3 red
4 绿色
5 red
6 black
7 白色
我想要计算黑色和红色项目的总数。结果应为5。
此代码工作正常,但如果我尝试添加红色则无效。
< pre lang =java> long count = DatabaseUtils.longForQuery(db, SELECT COUNT(*)FROM mytable WHERE columnA =' + black + ',null);
对不起,我的英文不好,谢谢你的帮助...
我尝试了什么:
long count = DatabaseUtils.longForQuery(db,SELECT COUNT(*)FROM mytable WHERE columnA =('+black+'AND'+ red+),null);
SELECT somecolumn,someothercolumn,COUNT(*)
FROM my_table
GROUP BY somecolumn,someothercolumn
SQLite:count函数 [ ^ ]
select type ,count( type )来自 表 组 按 型跨度>;
For example :
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.
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);
SELECT somecolumn,someothercolumn, COUNT(*)
FROM my_table
GROUP BY somecolumn,someothercolumn
SQLite: count Function[^]
select type, count(type) from table group by type;
这篇关于在sqlite中计算一个列中的多项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!