Jump to content

optimize query (4 subqueries)


tail

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.