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! 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. 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! Link to comment https://forums.phpfreaks.com/topic/189881-optimize-query-4-subqueries/#findComment-1003242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.