例如:
id columnA 1 black 2 red 3 red 4 绿色 5 red 6 black 7 白色我想要计算黑色和红色项目的总数。结果应为5。 此代码工作正常,但如果我尝试添加红色则无效。 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 whiteI 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中计算一个列中的多项?
发布评论