Help with AVG()
| From: | Ron Piggott | Date: | Mon, 13 Jun 2011 23:20:14 +0000 |
| Subject: | Help with AVG() | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-47848@lists.php.net to get a copy of this message | ||
Hi Everyone
I am trying to figure out how to write a SELECT query that will give me the average of
bible_anagrams.views starting on the date specified in
bible_anagrams_rss_feed.rss_feed_date and the previous 6 calendar days
(for a total of 7 days). What I am trying to figure out is the average of how many times the
anagrams RSS Feed were accessed between June 1st and 7th, June 2nd and 8th, June 3rd and 9th, etc.
- There is 1 row for each date in the table bible_anagrams_rss_feed.
I tried the following syntax, but it is giving me an overall average, not by the date ranges:
SELECT AVG(bible_anagrams.views) AS average_views FROM
bible_anagrams INNER JOIN bible_anagrams_rss_feed ON
bible_anagrams.reference =
bible_anagrams_rss_feed.bible_anagrams_reference ORDER BY
bible_anagrams_rss_feed.rss_feed_date DESC LIMIT 7
I am wanting the query I am asking help for to be included as one of the mySQL results, where I have
indicated “AVERAGE VIEWS QUERY HERE” (although if there is a better way I am opening to learning
it):
SELECT bible_anagrams_rss_feed.rss_feed_date ,
bible_anagrams.reference,
bible_anagrams.bible_anagram_word ,
bible_anagrams.views ,
(
AVERAGE VIEWS QUERY HERE
) AS average_views
FROM bible_anagrams_rss_feed INNER JOIN bible_anagrams ON
bible_anagrams.reference =
bible_anagrams_rss_feed.bible_anagrams_reference
ORDER BY bible_anagrams_rss_feed.rss_feed_date DESC
Thanks for helping me,
Ron
The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info