Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- mysql user variables (in the same statement)


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
...


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4353491.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com