All pastes #920084 Raw Edit

Someone

public text v1 · immutable
#920084 ·published 2008-02-27 04:52 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;


-----------------------------------------------------------
select count(l.customer_code) as last_month,
       count(x.customer_code) as this_month,
       l.year,
       l.month
  from zz_store_activity_by_month t,
       zz_store_activity_by_month l,
       zz_store_activity_by_month x

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


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


137	137	2008	2
129	129	2008	1
148	148	2007	12
156	156	2007	11
...
..
.