tail Posted January 26, 2010 Share Posted January 26, 2010 Is there a way to optimize this query so I don't have to use so many subqueries? SELECT COUNT( hits ) AS `unique` , SUM( hits ) AS `total` , ( SELECT SUM( `hits` ) FROM `stats` WHERE `date` > UNIX_TIMESTAMP( ) -86400 ) AS `today` , ( SELECT SUM( `hits` ) FROM `stats` WHERE `date` > UNIX_TIMESTAMP( ) -604800 ) AS `week` , ( SELECT SUM( `hits` ) FROM `stats` WHERE `date` > UNIX_TIMESTAMP( ) -2419200 ) AS `month` , ( SELECT COUNT( * ) FROM `stats` WHERE `online` > UNIX_TIMESTAMP( ) - '600' ) AS `online` FROM `stats` Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/189881-optimize-query-4-subqueries/ Share on other sites More sharing options...
fenway Posted January 28, 2010 Share Posted January 28, 2010 Not really... there's no simple way to combine them. Quote Link to comment https://forums.phpfreaks.com/topic/189881-optimize-query-4-subqueries/#findComment-1002788 Share on other sites More sharing options...
tail Posted January 28, 2010 Author Share Posted January 28, 2010 Ok thanks anyways! Quote Link to comment https://forums.phpfreaks.com/topic/189881-optimize-query-4-subqueries/#findComment-1003242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.