如何计算列中的值(重复项除外)。我尝试这个代码,但我没有。谢谢你的帮助。 (对不起,我的英文不好)
long net = DatabaseUtils.longForQuery(db, "select date, count(*) from mytable GROUP BY date", null);
nettext.setText(String.valueOf(net));
For example:
+----+------------+
| id | date |
+----+------------+
| 1 | 2006-10-08 |
| 2 | 2006-10-08 |
| 3 | 2006-10-09 |
+----+------------+
There is two different date (2006-10-08 and 2006-10-09)
Result must be = 2
答案 0 :(得分:3)
这应该有效:
long net = DatabaseUtils.longForQuery(db, "select count(DISTINCT date) from mytable GROUP BY date", null);
答案 1 :(得分:1)
我找到了解决方案。谢谢m.aibin。
long net = DatabaseUtils.longForQuery(db, "select count(DISTINCT date) from mytable", null);