为什么此查询两个左联接返回相同的值?

时间:2018-09-27 14:32:48

标签: mysql amazon-rds

我在下面运行查询...

问题是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

0 个答案:

没有答案