Created
August 4, 2022 08:37
-
-
Save w-jerome/9720f9f2da826ae6ec0aec50b61dbefb to your computer and use it in GitHub Desktop.
Prestashop — Export Customer with SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
c.id_customer, | |
c.firstname, | |
c.lastname, | |
c.email, | |
c.active, | |
c.newsletter, | |
c.optin, | |
c.date_add, | |
gl.name as social_title, | |
s.name as shop_name, | |
c.company, | |
( | |
SELECT | |
SUM( | |
total_paid_real / conversion_rate | |
) | |
FROM | |
ps_orders o | |
WHERE | |
(o.id_customer = c.id_customer) | |
AND ( | |
o.id_shop IN ('1') | |
) | |
AND (o.valid = 1) | |
) as total_spent, | |
( | |
SELECT | |
con.date_add | |
FROM | |
ps_guest g | |
LEFT JOIN ps_connections con ON con.id_guest = g.id_guest | |
WHERE | |
g.id_customer = c.id_customer | |
ORDER BY | |
con.date_add DESC | |
LIMIT | |
1 | |
) as connect | |
FROM | |
ps_customer c | |
LEFT JOIN ps_gender_lang gl ON c.id_gender = gl.id_gender | |
AND gl.id_lang = 1 | |
LEFT JOIN ps_shop s ON c.id_shop = s.id_shop | |
LEFT JOIN ps_customer_group cg ON c.id_customer = cg.id_customer | |
LEFT JOIN ps_address addrss ON c.id_customer = addrss.id_customer | |
WHERE | |
(c.deleted = 0) | |
AND ( | |
c.id_shop IN ('1') | |
) | |
AND ( | |
cg.id_group IN (3) /* Group Ids array */ | |
) | |
AND ( | |
addrss.id_country IN (1) /* this id_country is Germany */ | |
) | |
ORDER BY | |
c.date_add DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
c.id_customer, | |
c.firstname, | |
c.lastname, | |
c.email, | |
c.active, | |
c.newsletter, | |
c.optin, | |
c.date_add, | |
gl.name as social_title, | |
s.name as shop_name, | |
c.company, | |
( | |
SELECT | |
SUM( | |
total_paid_real / conversion_rate | |
) | |
FROM | |
ps_orders o | |
WHERE | |
(o.id_customer = c.id_customer) | |
AND ( | |
o.id_shop IN ('1') | |
) | |
AND (o.valid = 1) | |
) as total_spent, | |
( | |
SELECT | |
con.date_add | |
FROM | |
ps_guest g | |
LEFT JOIN ps_connections con ON con.id_guest = g.id_guest | |
WHERE | |
g.id_customer = c.id_customer | |
ORDER BY | |
con.date_add DESC | |
LIMIT | |
1 | |
) as connect | |
FROM | |
ps_customer c | |
LEFT JOIN ps_gender_lang gl ON c.id_gender = gl.id_gender | |
AND gl.id_lang = 1 | |
LEFT JOIN ps_shop s ON c.id_shop = s.id_shop | |
LEFT JOIN ps_customer_group cg ON c.id_customer = cg.id_customer | |
WHERE | |
(c.deleted = 0) | |
AND ( | |
c.id_shop IN ('1') | |
) | |
AND ( | |
cg.id_group IN ('3') /* Group Ids array */ | |
) | |
ORDER BY | |
c.date_add DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment