mysql grouping by week

Viewed 26768

I have a table with the following fields:

  • id
  • amount_sale
  • the_date (unix timestamp integer)
  • payment_type (can be Cash, or Account)

I am trying to create a query that will group all sales by each week of the year, and then split the sum of amount_sales for each week on my page.

Example:

week 1 = $26.00  
week 2 = $35.00  
week 3 = $49.00

etc. I'm using this query but it's not working:

  SELECT SUM(`amount_sale`) as total 
    FROM `sales` 
   WHERE `payment_type` = 'Account' 
GROUP BY WEEK(`the_date`)
4 Answers
Related