Page is a not externally linkable
noyearzero - 6:33 pm on Aug 19, 2011 (gmt 0)
Thanks for your suggestion. I did a few tests and found this method is the fastest and provides the best caching results over the user variable method and doing subqueries instead of the join.
The only downside is I still have to repeat the bits of logic in the calculation for percentage, but its not that big of a deal with the help of PHP
SELECT
COUNT(IF(emails.status = 'sent', 1, NULL)) AS sent,
COUNT(IF(emails.opened = '1', 1, NULL)) AS opened,
(COUNT(IF(emails.opened = '1', 1, NULL)) / COUNT(IF(emails.status = 'sent', 1, NULL)) * 100) AS PERCENT
...