आप MySQL के पुराने संस्करणों में चर का उपयोग कर सकते हैं:
select t.*,
(@rn := if(@ce = customer_email, @rn + 1,
if(@ce := customer_email, 1, 1)
)
) as occurrences
from (select t.*
from t
order by customer_email, created_at
) t cross join
(select @ce := '', @rn := 0) params;
MyQL 8+ में, मैं row_number()
. का सुझाव दूंगा :
select t.*,
row_number() over (partition by customer_email order by created_at) as occurrences
from t;