sqlite COUNT分组返回1?

时间:2016-06-20 19:19:39

标签: sqlite appcelerator

我正在尝试计算sqliteGROUP by msisdn中的联系人。

没有GROUP BY msisdn返回210 GROUP BY msisdn返回1

var queryTotal   = db.execute('SELECT cid , COUNT(*) AS totalFriends FROM contact WHERE deleted = 0 AND synced = 1 GROUP BY msisdn');
var total = queryTotal.fieldByName('totalFriends');

            alert(total);

这里有什么问题!

2 个答案:

答案 0 :(得分:1)

您确定您的查询是否正确?

 SELECT cid , COUNT(*) AS totalFriends FROM contact WHERE deleted = 0 AND synced = 1 GROUP BY msisdn

尝试:

GROUP BY cid

答案 1 :(得分:0)

您应该在所选列中包含msisdn:

SELECT msisdn ,COUNT(*)AS totalFriends FROM contact WHERE deleted = 0 AND synced = 1 GROUP BY msisdn