【问题标题】:Get customer names, emails and phone numbers from Magento 1.9 database从 Magento 1.9 数据库中获取客户姓名、电子邮件和电话号码
【发布时间】:2018-06-16 12:07:59
【问题描述】:

我有两种不同的 SQL 代码,一种用于获取用户名和电子邮件,另一种用于获取电话号码。

您能帮忙将它与一个脚本结合起来,以便获得用户名、电子邮件和电话号码的列表吗?

这是获取用户名和电子邮件的查询(@Steve Robbins):

select ce.entity_id, concat(cevf.value, ' ', cevl.value) fullname, ce.email
from customer_entity ce
inner join customer_entity_varchar cevf
    on ce.entity_id = cevf.entity_id
inner join eav_attribute eaf
    on eaf.attribute_id = cevf.attribute_id
inner join customer_entity_varchar cevl
    on ce.entity_id = cevl.entity_id
inner join eav_attribute eal
    on eal.attribute_id = cevl.attribute_id
inner join eav_entity_type eet
    on eet.entity_type_id = eal.entity_type_id = eaf.entity_type_id
where
    eet.entity_type_code = 'customer'
    and eaf.attribute_code = 'firstname'
    and eal.attribute_code = 'lastname'
order by ce.entity_id

这个只用于电话号码(@zaka47):

select customer_address_entity_varchar.value from customer_address_entity_varchar
left join  customer_entity on customer_entity.entity_id = "your_customer_id"
left join  customer_address_entity on customer_address_entity.parent_id = customer_entity.entity_id
join eav_attribute on eav_attribute.attribute_code="telephone"
where customer_address_entity_varchar.attribute_id = eav_attribute.attribute_id

我的目标是得到如下表结构:

------------------------------------------------------
Full Name  |   Email Address     | Phone Number 
------------------------------------------------------
David Ros  |   david@email.com   | 02-30493929  
Joe Pratt  |   joe@email.com     | 03-20392030   
------------------------------------------------------

谢谢。

【问题讨论】:

  • 提供带有示例数据(格式化文本)的表结构和基于示例数据(格式化文本)的预期输出。我们不是在这里对您的 SQL 代码进行逆向工程并将其转换为一个有效的 SQL 查询
  • 感谢@RaymondNijland 的评论,我更新了我的帖子,希望现在更清楚。当我运行上述查询时,我在同一个表结构中获得信息,但它们中的每一个都缺少其他请求的信息。不知道怎么搭配。

标签: mysql magento


【解决方案1】:

在您的第一个查询中包含另外 2 个连接(customer_address_entity_varchar 和 eav_attribute)以获取属性电话

select ce.entity_id, 
       concat(cevf.value, ' ', cevl.value) fullname,
       ce.email,
       caev.value telephone
from customer_entity ce
inner join customer_entity_varchar cevf
    on ce.entity_id = cevf.entity_id
inner join eav_attribute eaf
    on eaf.attribute_id = cevf.attribute_id
inner join customer_entity_varchar cevl
    on ce.entity_id = cevl.entity_id
inner join eav_attribute eal
    on eal.attribute_id = cevl.attribute_id
inner join eav_entity_type eet
    on eet.entity_type_id = eal.entity_type_id = eaf.entity_type_id
inner join customer_address_entity_varchar caev
    on ce.entity_id = caev.entity_id
inner join eav_attribute eat 
    on caev.attribute_id = eat.attribute_id 
where
    eet.entity_type_code = 'customer'
    and eaf.attribute_code = 'firstname'
    and eal.attribute_code = 'lastname'
    and eat.attribute_code='telephone'
order by ce.entity_id

【讨论】:

    【解决方案2】:

    上面的答案还是错了,客户实体id是customer_address_entity中的link,而不是customer_address_varchar。

    当前查询如下:

    select ce.entity_id, 
       concat(cevf.value, ' ', cevl.value) fullname,
       ce.email,
       caev.value telephone from customer_entity ce
    inner join customer_entity_varchar cevf
        on ce.entity_id = cevf.entity_id
    inner join eav_attribute eaf
        on eaf.attribute_id = cevf.attribute_id
    inner join customer_entity_varchar cevl
        on ce.entity_id = cevl.entity_id
    inner join eav_attribute eal
        on eal.attribute_id = cevl.attribute_id
    inner join eav_entity_type eet
        on eet.entity_type_id = eal.entity_type_id = eaf.entity_type_id
    inner join customer_address_entity cae 
        on cae.parent_id = ce.entity_id
    inner join customer_address_entity_varchar caev
        on cae.entity_id = caev.entity_id
    inner join eav_attribute eat 
        on caev.attribute_id = eat.attribute_id 
    where
        eet.entity_type_code = 'customer'
        and eaf.attribute_code = 'firstname'
        and eal.attribute_code = 'lastname'
        and eat.attribute_code='telephone'
    order by ce.entity_id desc limit 1
    

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 2018-03-16
      相关资源
      最近更新 更多