hi everybody,i'm new here and in mysql world...trying to learn something new everyday. I'm working on a bi platform based on mysql reports and i have a problem with one of them.

I want the report to tell me sales of a shop by year and month and i want to calculate the change between sales of the months. For example

shop year month sales diff
142 2015 may 11.000 +10%
142 2015 abr 10.000 ....

I tried to set a variable (@prev_val) but when i execute the query it gives an error.

If somebody could help me...

Thanks in advance




set @prev_val=0;

SELECT
d1.ID_shop,
year(d1.Date),
month(d1.date),
sum(d1.salesl),
sum(d1.sales)-@prev_val ,
@prev_val:=sum(d1.sales)
FROM
dati_giornalieri d1
WHERE
year(d1.date)=2015 and
d1.id_shop=142
group by
month(d1.date)