Re: RE:[PHP-DB] How do I do math with a UNION ALL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for the suggestion.  This is the actual query that I implemented:  Amazing how this works.  Ron

SELECT SUM( `impressions_total` ) AS impressions_total , SUM( `usage_total` ) AS usage_total FROM (                            

(

SELECT IF ( SUM( `web_advertisements_our_clients_usage`.`impressions` ) , SUM( `web_advertisements_our_clients_usage`.`impressions` ) , 0 ) AS impressions_total, IF ( SUM( `web_advertisements_our_clients_usage`.`usage` ) , SUM( `web_advertisements_our_clients_usage`.`usage` ) , 0 ) AS usage_total FROM `web_advertisements_our_clients_usage` WHERE `web_advertisements_our_clients_reference` =  $web_advertisements_our_clients_reference AND `month` = $stats_month AND `year` = $stats_year LIMIT 1

) UNION ALL (

SELECT `impressions` AS impressions_total, `usage` as usage_total FROM `web_advertisements_our_clients` WHERE `reference` = $web_advertisements_our_clients_reference LIMIT 1

)

) AS monthly_stats_total;

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info  


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux