Re: Analyzing dates in a table
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Analyzing dates in a table

From: ZeldorBlat <zeldorblat@gmail.com>
Date: Thu Sep 08 2005 - 00:13:31 CEST

First off, you probably can't use the word 'Date' as a column name.
Aside from that, it isn't too tough:

Hits today:

select sum(pageViews)
from tbl_hits
where Date = curdate()

Hits this week:

select sum(pageViews)
from tbl_hits
where weekofyear(Date) = weekofyear(curdate())
   and year(Date) = year(curdate())

If you want to count total hits for some arbitrary interval:

select sum(pageViews)
from tbl_hits
where Date between '1/5/2005' and '7/16/2005'

And, if you want to see these broken out by each page, just add
'pageename' to the select list and add a 'group by pagename' at the end
of the query.
Received on Tue Oct 18 02:20:03 2005