我正在尝试对表“apst_mailings”运行查询,该表存储了我们发送给订阅者的每个时事通讯的内容。每次我们尝试向个人发送电子邮件时,我们都会在 apst_mailings_accuses 中插入一行,报告发送的时间和状态,以及新信的 ID。我想列出时事通讯并计算每个已发送和成功发送的总数。
SELECT m.id AS code_mailing,
COUNT(a.adh_code) AS num, COUNT(b.adh_code) AS succes
FROM apst_mailings AS m
LEFT OUTER JOIN apst_mailings_accuses AS a
ON a.id_mailing = m.id
LEFT OUTER JOIN apst_mailings_accuses AS b
ON b.id_mailing = m.id
AND b.etat = 'succes'
GROUP BY m.id
它只是永远挂起服务器。我已经在单独的查询中尝试了每个连接,并且没有问题:
// Counts the email sent per mailing
SELECT m.id AS code_mailing,
COUNT(a.adh_code) AS num
FROM apst_mailings AS m
LEFT OUTER JOIN apst_mailings_accuses AS a
ON a.id_mailing = m.id
GROUP BY m.id
SELECT m.id AS code_mailing,
COUNT(b.adh_code) AS succes
FROM apst_mailings AS m
LEFT OUTER JOIN apst_mailings_accuses AS b
ON b.id_mailing = m.id
AND b.etat = 'succes'
GROUP BY m.id
我可以拆分我的查询,但它不起作用的原因真的让我很困扰。谁能解释一下?
谢谢!