php-db | 2002091

RE: [PHP-DB] A group count question From: John Holmes (holmes072000 <email protected>)
Date: 09/14/02

> I have a table that I would like to show some stats based on num
> messages collated to date posted.
>
> I think I need something like
>
> Count(replies) where date= month(dateposted)
>
> All I need is to show that say that in month 8, 500 messages were sent
> and in month 9 300 messages were sent and so on.

If you know the month, then you would do this:

SELECT COUNT(*) FROM table WHERE MONTH(date_column) = $month;

If you want a rollup for all months, then:

SELECT COUNT(*) FROM table GROUP BY MONTH(date_column);

If you want a rollup for the current year:

SELECT COUNT(*) FROM table WHERE YEAR(date_column) = year(CURDATE())
GROUP BY MONTH(date_column)

HTH

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php