在sqlite中计算一个列中的多项? [英] Count muttiple items in the sqlite a column ?

查看:105
本文介绍了在sqlite中计算一个列中的多项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆