in reply to Best way to implement a stats counter ("this week" AND "all-time")

isync:

Have a counter table with a row for each day containing a hit count. I use the date in form YYYYMMDD as a key, and a simple int as the counter. For each hit, just find the current date and increment the bucket. Each night, add all days older than 7 days to bucket '00000000'.

So for "visits this week" you'd use:

select sum(counter) from hit_counts where hit_date > dateadd(d,-7,getdate())

and for "visits all time":

select sum(counter) from hit_counts

Note: I've used Sybase/MS SQL Sever syntax here, may vary for other DB servers....

...roboticus

Replies are listed 'Best First'.
Re^2: Best way to implement a stats counter ("this week" AND "all-time")
by roboticus (Chancellor) on Sep 13, 2007 at 10:35 UTC
    ...and when you add to bucket "00000000" be sure to delete the (no longer needed) rows you're adding to it!

    ...roboticus