On 10 Jul 2009, at 03:44, sangprabv wrote:
SELECT count(sql_id) AS total, DATE_FORMAT(insertdate, '%H:%i' ) AS mydate FROM momt WHERE 1=1 AND insertdate BETWEEN DATE_ADD(NOW(),INTERVAL - 1 HOUR) AND NOW() AND (sms_type = 1 OR sms_type =2) GROUP BYmydate ORDER BY insertdate
Firstly do an EXPLAIN on that and make sure it's got and is using appropriate indexes. Straight off a couple of small changes should help:
SELECT count(*) AS total, DATE_FORMAT(insertdate, '%H:%i' ) AS mydate FROM momt WHERE 1=1 AND insertdate > DATE_ADD(NOW(), INTERVAL - 1 HOUR) AND (sms_type = 1 OR sms_type =2) GROUP BY mydate ORDER BY insertdate This assumes that insertdate can't be in the future... Marcus -- Marcus Bointon Synchromedia Limited: Creators of http://www.smartmessages.net/ UK resellers of i...@hand CRM solutions mar...@synchromedia.co.uk | http://www.synchromedia.co.uk/
smime.p7s
Description: S/MIME cryptographic signature