Du kan bruge følgende forespørgsel:
SELECT CONCAT(EXTRACT(MONTH FROM startedPayingDate), '-',
EXTRACT(YEAR FROM startedPayingDate)) AS "Month",
COUNT(*) AS "Total AB Paying Customers"
FROM (
SELECT customer_id, MIN(created_at) AS startedPayingDate
FROM customerusermap AS cm
WHERE NOT EXISTS (SELECT 1
FROM users AS u
WHERE cm.user_id = u.id)
GROUP BY customer_id ) AS t
GROUP BY 1
Jeg brugte en NOT EXISTS
operatør for at udelukke registreringer, der vedrører "at betale for sig selv" kunder (hvis det virkelig er din hensigt).
Når du har fået MIN(created_at)
dato pr. customer_id
, så kan du nemt tælle per dato i en ydre forespørgsel.