yesterday I'd posted something similar to this and it was successfully answered.
after moving onto the next step i've hit a bit of a brick wall so i'm creating a new post...
i have the following table '11_email_tracker', with tracked emails...
campaign | open | clicks
A | 1 | 2
A | 2 | 0
A | 0 | 0
A | 1 | 1
A | 0 | 0
A | 3 | 0
A | 0 | 0
A | 2 | 4
B | 0 | 0
B | 5 | 2
B | 0 | 0
B | 6 | 1
B | 0 | 0
B | 2 | 0
B | 1 | 0
B | 0 | 0
etc...
I can GROUP by campaign and COUNT how many emails were sent, for example...
campaign | sent |
A | 12000 |
B | 30000 |
and to do this i'm using the following query...
but my next step is to achieve the following...
campaign | sent | opened | clicked | open_rate% | click_rate%
A | 12000 | 3000 | 416 | 25 | 13.8
B | 30000 | 5000 | 535 | 16.6 | 10.7
all in the same while loop and query...
i must COUNT how many emails were sent and how many were opened,
but i must only count the number of emails opened with a value greater than 0 in column 'open'
and the same for clicks, i must count the number of emails clicked with a value greater than 0 in column 'clicks'
plus i must calculate open rate % and CTR% in the same query
r937 showed me how to calculate open rate % and CTR% for a similar issue i had,
but now i need to modify my query and taking it once step at a time i'm first trying to count the number of emails opened and clicked,
i tried doing the following but it doesn't work... although i thought it must be on the right track?
after moving onto the next step i've hit a bit of a brick wall so i'm creating a new post...
i have the following table '11_email_tracker', with tracked emails...
campaign | open | clicks
A | 1 | 2
A | 2 | 0
A | 0 | 0
A | 1 | 1
A | 0 | 0
A | 3 | 0
A | 0 | 0
A | 2 | 4
B | 0 | 0
B | 5 | 2
B | 0 | 0
B | 6 | 1
B | 0 | 0
B | 2 | 0
B | 1 | 0
B | 0 | 0
etc...
I can GROUP by campaign and COUNT how many emails were sent, for example...
campaign | sent |
A | 12000 |
B | 30000 |
and to do this i'm using the following query...
$sql_email_rpt = "SELECT COUNT(email_campaign) ";
$sql_email_rpt .= "FROM 11_email_tracker ";
$sql_email_rpt .= "GROUP by email_campaign ";
$sql_email_rpt .= "ORDER by email_campaign DESC";
but my next step is to achieve the following...
campaign | sent | opened | clicked | open_rate% | click_rate%
A | 12000 | 3000 | 416 | 25 | 13.8
B | 30000 | 5000 | 535 | 16.6 | 10.7
all in the same while loop and query...
i must COUNT how many emails were sent and how many were opened,
but i must only count the number of emails opened with a value greater than 0 in column 'open'
and the same for clicks, i must count the number of emails clicked with a value greater than 0 in column 'clicks'
plus i must calculate open rate % and CTR% in the same query
r937 showed me how to calculate open rate % and CTR% for a similar issue i had,
but now i need to modify my query and taking it once step at a time i'm first trying to count the number of emails opened and clicked,
i tried doing the following but it doesn't work... although i thought it must be on the right track?
$sql_email_rpt = "SELECT
COUNT(email_campaign),
COUNT(open) > 0,
COUNT(clicks) > 0,
100.0 * COUNT(open) / COUNT(email_campaign) AS `open_rate%`,
100.0 * COUNT(clicks) / COUNT(open) AS `click_rate%`
";
$sql_email_rpt .= "FROM 11_email_tracker ";
$sql_email_rpt .= "GROUP by email_campaign ";
$sql_email_rpt .= "ORDER by email_campaign DESC";