how can I get the number of new/first time customers per week from my magento store with an SQL query?

Does somebody knows that?



You want to retrieve customers which accounts are no older than 7 days, right?

If this is it, it's a pretty easy SQL Query. Something like this can do the job:

FROM customer_entity
`created_at` > DATE_SUB( NOW( ) , INTERVAL 7 
LIMIT 0 , 30

Ofcourse then you receive whole records, not just the count of new customers.

If you'd like to retrieve just the count of them use:

SELECT COUNT(*) FROM customer_entity WHERE (`created_at` > DATE_SUB(now(), INTERVAL 365 DAY));

Here's a great answer from another question how timestamp queries should be done: https://stackoverflow.com/a/17198760/4022683

| improve this answer | |
  • Hey @versedi thanks for the quick response. Can I also group them by week, so that I can create a visualization like "Calendar Week 30: 7 customers, Calendar Week 31: 10 customer" ? – Torben Mar 22 '16 at 10:41
  • Sure, this would take some time to prepare but you could create a simple function where you'd pass the time-interval as parameter. You can extract number of week using this: stackoverflow.com/a/18400181/4022683 – versedi Mar 22 '16 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.