我有一张桌子,我需要从中获取联系人。所以我使用一个复杂的查询来从我的“sms”表中检索所有的联系人。
但是,它应该只计算提供的“imei”字段的记录,但我的查询会不断返回特定联系人的所有计数。
下面是使用的代码:
$sql = $this->db->query('
SELECT
t1.mnumber AS t1_number, t1.mcontent AS t1_content, t1.mcontact as t1_contact, SUM(t2.TOTAL) AS mTotal
FROM
sms t1
JOIN
(SELECT
mContent, mcontact, COUNT(mNumber) AS TOTAL, mnumber, MAX(mID) mID
FROM
sms
GROUP BY mContact) t2 ON t1.mcontact = t2.mcontact
AND t1.mid = t2.mid
WHERE t1.mIMEI = ' . (IMEI) . '
GROUP BY t1.mContact
ORDER BY t1.mid DESC');
return $sql->result();