Jump to content

Module - last order date per customer


Recommended Posts

This SQL query will give you that. You can then export to CSV using your DB manager. 

SELECT c.id_customer, c.firstname, c.lastname, orders.date_add AS last_order
FROM ps_customer c 
LEFT JOIN ( 
	SELECT o.id_customer, o.date_add 
	FROM ps_orders o 
	INNER JOIN (
		SELECT id_customer, max(date_add) as mostRecent
		FROM ps_orders
		GROUP BY id_customer 
	) ord ON o.id_customer = ord.id_customer AND o.date_add = ord.mostRecent 
) orders ON c.id_customer = orders.id_customer

Customers that have not placed an order will have a null value on last_order field.

  • Like 1
Link to comment
Share on other sites

  • 10 months later...

This SQL query will give you that. You can then export to CSV using your DB manager. 

SELECT c.id_customer, c.firstname, c.lastname, orders.date_add AS last_order
FROM ps_customer c 
LEFT JOIN ( 
	SELECT o.id_customer, o.date_add 
	FROM ps_orders o 
	INNER JOIN (
		SELECT id_customer, max(date_add) as mostRecent
		FROM ps_orders
		GROUP BY id_customer 
	) ord ON o.id_customer = ord.id_customer AND o.date_add = ord.mostRecent 
) orders ON c.id_customer = orders.id_customer

Customers that have not placed an order will have a null value on last_order field.

Hi there, I am getting the following error in sql manager:

 

"Undefined "checkedSelect" error"

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...