本文介绍了在sqlite中计算一个列中的多项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 例如: 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 columnA1 black2 red3 red4 green5 red6 black7 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_tableGROUP BY somecolumn,someothercolumnSQLite: count Function[^]select type, count(type) from table group by type; 这篇关于在sqlite中计算一个列中的多项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 15:01
查看更多