在sqlite中计算一个列中的多项?

编程入门 行业动态 更新时间:2024-10-14 18:13:28
本文介绍了在sqlite中计算一个列中的多项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

例如:

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 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中计算一个列中的多项?

本文发布于:2023-11-21 23:41:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多项   sqlite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!