Re: 7-day average

2010-03-18 Thread Brian Dunning
You're exactly right, that's an important point that I neglected when putting together my example. Good catch. On Mar 18, 2010, at 11:27 AM, Chris W wrote: > I think I would change the math. Since there are several days in there where > there are no hits, that should in my opinion count again

Re: 7-day average

2010-03-18 Thread Chris W
I changed the names slightly when I tested it but here is the query that gives the result you want... SELECT a.`AccountID`, a.`company`, sum(h.hits), count(h.AccountID), sum(h.hits)/count(h.AccountID) AS AvgHits FROM account a JOIN hitsperday h using (AccountID) WHERE `date` < DATE(now()) AND

Re: 7-day average

2010-03-18 Thread Jigal van Hemert
Brian Dunning wrote: My brain just squirted out my ear trying to figure this out, so maybe one of you can help me scoop it back up. Yummy, fresh brain! ;-) I have a table of accounts, and a table of hits-per-day per account. I'm trying to sort my accounts by the most hits-per-day, averaged ov

7-day average

2010-03-18 Thread Brian Dunning
My brain just squirted out my ear trying to figure this out, so maybe one of you can help me scoop it back up. I have a table of accounts, and a table of hits-per-day per account. I'm trying to sort my accounts by the most hits-per-day, averaged over the preceding 7 days (8 days ago through yes