Re: Subtracting months in MySQL
| From: | Becoming Digital | Date: | Tue, 20 May 2003 11:56:38 +0000 |
| Subject: | Re: Subtracting months in MySQL | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27919@lists.php.net to get a copy of this message | ||
Can you elaborate more on how your tables are setup, perhaps even paste DESCRIBE
output? I've got a potential solution but something isn't making sense to me so
it just my fall on its face.
Edward Dudlik
Becoming Digital
www.becomingdigital.com
----- Original Message -----
From: "Lisi" <lists@shemeshdirectory.co.il>
To: "PHP-DB" <php-db@lists.php.net>
Sent: Tuesday, 20 May, 2003 04:50
Subject: [PHP-DB] Subtracting months in MySQL
I have a table that stores a daily summary of page hits. I need to be able
to summarize this data by month, which I've done with the following query:
SELECT
MONTHNAME(date) as month,
YEAR(date) as year,
SUM(count) as count
FROM pagehits
GROUP BY
YEAR(date),
MONTHNAME(date)
ORDER BY
YEAR(date),
MONTH(date)
I then need to limit this to the previous 12 months.
What's the best way to do this?
1) Using PHP (mktime, date) to get the defining months and plugging into
the query
2) Using MySQL's built in functions (BETWEEN, DATE_SUB) to figure this out
as part of the query (preferable I think)
I know there many different ways to go about this, I'm a little confused
about putting the parts to work together.
Thanks,
-Lisi
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php