Andrew Kreps wrote:
>> I have a MySQL db with a datetime field containing the
>> date and time of the sale. I want to query for a simple
>> report that shows total sales by month.
>
This one worked for me, on MySQL 3.23.xx.  I hope it's closer to what you need.

select sum(ordersubtotal), date_format(orderdate, '%Y-%m') as odate
from orders group by odate

Also,

SELECT SUM(ordersubtotal), YEAR(orderdate), MONTH(orderdate) FROM orders GROUP BY YEAR(orderdate), MONTH(orderdate)

If you wanted the date parts in separate columns or wanted to limit to specific months. If you ever want to group by week, YEARWEEK() will come in handy, btw.

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

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



Reply via email to