Select multiple terms from one query

Hi
I use a stats counter in a CMS to allow the client to see how many visits certain pages have received over the last 30 / 60 and 90 days.
Il currently doing this in 3 queries, is there a way of combining all this into one query ?

OK, got it working with

SELECT SUM(CASE WHEN DATEDIFF(CURDATE(), Time) 
                     BETWEEN  0 AND 30 THEN 1 ELSE 0 END) D30,
       SUM(CASE WHEN DATEDIFF(CURDATE(), Time) 
                     BETWEEN 31 AND 60 THEN 1 ELSE 0 END) D60,
       SUM(CASE WHEN DATEDIFF(CURDATE(), Time) 
                     BETWEEN 61 AND 90 THEN 1 ELSE 0 END) D90
  FROM page_stats_t
 WHERE Time BETWEEN CURDATE() - INTERVAL 90 DAY AND CURDATE()
  AND Page_ID = 1921
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.