Link to home
Create AccountLog in
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!
Avatar of Sharath S
Sharath S
Flag of United States of America image

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

Open in new window

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.
Avatar of apocalip30
apocalip30

ASKER

Yes it worked fine, thanks !

 ¿could we include number of order per customer?
ASKER CERTIFIED SOLUTION
Avatar of Branislav Borojevic
Branislav Borojevic
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
great thanks!
thks