我正在尝试计算sqlite
表GROUP 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);
这里有什么问题!
答案 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