Someone
public text v1 · immutableselect 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;