Jump to content

How would I calculate sales by month


Ihsaan

Recommended Posts

I assume you really mean all the sales for the month of July in 2012 (or some particular year), correct? If you had data over multiple years you wouldn't want the sales total for July from all years.

 

So, you need to extract the month and year from the date field and GROUP BY those two values (if getting the totals for all year/month combos:

 

SELECT SUM(total), MONTH(date_created) as month, YEAR(date_created) as YEAR
FROM table_name
GROUP BY year, month

Thanks so much. I however would want the final php outcome to look something like this

 

Month      Total

==============

July 12            1000

Aug 12            850

 

etc...

I'm 100% sure that you don't have an idea what you're doing, right?  ;)

Thanks so much. I however would want the final php outcome to look something like this

 

Month      Total

==============

July 12            1000

Aug 12            850

 

etc...

 

OK, how does the first solution I provided not work for that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.