All pastes #910790 Raw Edit

Someone

public text v1 · immutable
·published 2008-02-20 05:26 UTC
rendered paste body
select  year(a.invoice_date) as y, month(a.invoice_date) as m, count(distinct a.customer_code) as repeatbuy from sh_transaction a 
inner join sh_transaction b
on a.customer_code = b.customer_code
where 
year(a.invoice_date) * 12 + month(a.invoice_date)+1  = year(b.invoice_date) * 12 + month(b.invoice_date) and

year(a.invoice_date)  >= 2007


group by year(a.invoice_date), month(a.invoice_date)
order by y, m;