MYSQL:摘要数据查询SQL

时间:2014-07-24 18:47:38

标签: mysql sql join summary

所以,我有这个:

SELECT COUNT(mailing_recipient_id) AS Total_Recipient, 
(SELECT COUNT(mailing_recipient_click_id) 
ORDER BY(mailing_recipient_click_type_id)) AS Open_Count, 
(SELECT COUNT(cons_action_contribution_id)) AS Total_Donations, 
(SELECT COUNT(cons_id) ORDER BY cons_action_contribution_id) AS Donations_Per_Recipient 
FROM cons LEFT JOIN mailing_recipient
ON cons.cons_id =mailing_recipient.cons_id
JOIN mailing
ON mailing_recipient.mailing_id = mailing.mailing_id
JOIN mailing_recipient_click
ON mailing_recipient_click.mailing_recipient_id = mailing_recipient.mailing_recipient_id
JOIN cons_action_contribution 
ON cons_action_contribution.con_id = cons.cons_id
GROUP BY(mailing_id);

我希望实现的是一个摘要,包括收件人数,开放计数,每个收件人打开,点击次数,每个收件人的点击次数,捐赠次数以及每个收件人的捐款。

这不是我得到的,我不确定为什么。

mailing_recipient_click_id显示是否有人打开/点击了该电子邮件。

mailing_recipient_click_type_id(1 =点击,2 =打开)

我现在没有拿到桌子,但我希望能达到以下目的:

Mailing  Recipient    Open    Open_per    Clicks    Click_per    Donation    Donation_per  
1        10000       5000    5           4000      3            500         2  
2        5000        2500    1           4000      1            50          1  

0 个答案:

没有答案