如何使用prestashop的backofficesql管理器从两个不同的表导出用户数据?

pkmbmrz7  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(323)

我不擅长sql,所以我需要帮助导出我的客户的名字,电子邮件地址,他们的国家,如果可能的话,他们最后一次访问商店。
我通过以下查询获得了电子邮件和名字:

SELECT firstname, lastname, email, active FROM  psdb_customer

据我所知,由于另一个数据存储在不同的db表中,所以我应该使用join从两个表中获取数据,但我还没有弄清楚如何获取数据
欢迎任何帮助

fd3cxomn

fd3cxomn1#

rolige的答案正是我想要的。
下面是另一个允许按国家(使用id\u 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
hfwmuf9z

hfwmuf9z2#

过去,我在prestashop论坛上帮助过一些类似的人。这个查询应该有效,只需记住,要获得客户的国家/地区,他们至少应该注册一个地址,当然我使用的是默认的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

相关问题