Question : Quarter Reports Php and Mysql

Hi All

I have a table that has the following colums date,sales and purchases .

I need mysql or php code that will give me quarter report's depending on the start of the company's
financial year so it can be in a config file say $financial_start = 2010-05-01 ;

It then needs to work out the quarter sales , and purchases and give it to me in a table format .

All help will be appreciated .

Thanks
Thomas

Answer : Quarter Reports Php and Mysql

Correction, the start of period should be in the query a total of 3 times:

select date_add($periodstart, INTERVAL quarter*3 MONTH) as StartOfQuarter, `countsales`, countpurchases
from
(
select
  floor(period_diff(date_format(`date`, '%Y%m'), date_format($periodstart, '%Y%m')) / 3) as quarter,
  count(sale) as countsales, count(purchases) as countpurchases
from tbl
group by floor(period_diff(date_format(`date`, '%Y%m'), date_format($periodstart, '%Y%m')) / 3)
) sq
order by 1
Random Solutions  
 
programming4us programming4us