All pastes #919978 Raw Edit

Someone

public text v1 · immutable
#919978 ·published 2008-02-27 03:30 UTC
rendered paste body
select count(l.customer_code) as last_month,  l.year,l.month
  from zz_store_activity_by_month t, zz_store_activity_by_month l

where
 t.customer_code = l.customer_code and
 t.year * 12 + t.month = l.year * 12 + l.month - 1


group by l.year ,l.month 
order by l.year desc ,l.month desc;

select count(customer_code) as this_month, year,month 
from zz_store_activity_by_month
group by year,month
order by year desc ,month desc;