我在下面运行查询...
问题是Total Recommendations
返回错误的值,它返回的值与Total Contacts
... Total Contacts
是正确的... Total Recommendations
为什么计算不正确?谢谢
SELECT
ca.id,
ca.user_id,
ca.account_name,
COUNT(c.id) AS 'Total Contacts',
COUNT(pr.id) AS 'Total Recommendations'
FROM connected_accounts ca
LEFT JOIN contacts c
ON ca.id = c.connected_account_id
AND c.contact_type = 'email'
LEFT JOIN peer_recommendations pr
ON ca.id = pr.connected_account_id
WHERE ca.resource_type = 'calendar.readonly'
GROUP BY ca.id, ca.user_id, ca.account_name
ORDER BY ca.id DESC
LIMIT 8