如何使用 Prestashop 的后台 sql 管理器从两个不同的表中导出用户数据?

How to export user data from two different tables using the backoffice sql manager of Prestashop?

我不擅长 sql,所以我需要帮助导出我客户的名字、电子邮件地址、他们的国家,如果可能的话,他们最后一次访问商店的时间。

我通过使用此查询设法获得了电子邮件和名字:

SELECT firstname, lastname, email, active FROM  psdb_customer

据我了解,由于其他数据存储在不同的数据库中 table,我应该使用连接从两个 table 中获取数据,但我无法做到弄清楚如何

欢迎任何帮助

过去,我曾在 PrestaShop forum 中帮助过某人做类似的事情。此查询应该有效,请记住,要获得客户的国家/地区,他们应该至少注册一个地址,当然我使用的是默认的 db 前缀:

SELECT a.`firstname`,
       a.`lastname`,
       a.`email`,

  (SELECT c.`date_add`
   FROM `ps_guest` g
   LEFT JOIN `ps_connections` c ON c.`id_guest` = g.`id_guest`
   WHERE g.`id_customer` = a.`id_customer`
   ORDER BY c.`date_add` DESC LIMIT 1) AS `last_activity`,

  (SELECT cl.`name`
   FROM `ps_address` ad
   LEFT JOIN `ps_country_lang` cl ON cl.`id_country` = ad.`id_country`
   WHERE ad.`id_customer` = a.`id_customer`
   ORDER BY ad.`id_address` DESC LIMIT 1) AS `country_name`

FROM `ps_customer` a

Rolige 的回答正是我要找的。

这是另一个允许按国家过滤结果的查询(使用 id_country)

SELECT SQL_CALC_FOUND_ROWS  a.`id_address`,
a.firstname as firstname,
a.lastname as lastname,
cl.id_country as country, cl.`name` as country
FROM `ps_address` a
LEFT JOIN `ps_country_lang` cl ON (cl.`id_country` = a.`id_country`
AND cl.`id_lang` = 1)
LEFT JOIN `ps_customer` c ON a.id_customer = c.id_customer
WHERE 1 AND a.id_customer != 0
AND c.id_shop IN (1)
AND a.`deleted` = 0
AND cl.`id_country` = '8'
ORDER BY a.`id_address` ASC