Avatar of apocalip30
apocalip30
 asked on

Magento 1.9.2 SQL Query to retrive buyers from our customers

We need to retrive form our database all the buyers form our customers during a range of dates.

That is all the customers that bought something duting a range of dates, we are using Magento 1.9.2

Thank you!
MagentoMySQL Server

Avatar of undefined
Last Comment
apocalip30

8/22/2022 - Mon
Sharath S

SELECT * FROM Customers 
WHERE purchase_date BETWEEN 'start_date' AND 'end_date'

Open in new window

Branislav Borojevic

SELECT `e`.*, MAX(o.created_at) AS `last_order_date` FROM `customer_entity` AS `e` LEFT JOIN `sales_flat_order` AS `o` ON o.customer_id = e.entity_id WHERE (`e`.`entity_type_id` = '1') GROUP BY `e`.`entity_id` HAVING (last_order_date < '2014-03-26') OR (last_order_date IS NOT NULL)

Open in new window


This will return all customers that made a purchase from the last_order_date (you can set your own date) and the date when you make the query.

Hope it helps.

I tested it myself, it should work and return what you need.

Let me know if it works for you.
apocalip30

ASKER
Yes it worked fine, thanks !

 ¿could we include number of order per customer?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Branislav Borojevic

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
apocalip30

ASKER
great thanks!
apocalip30

ASKER
thks