mysql - prestashop 1.6 中具有过滤天数的休眠用户

标签 mysql prestashop prestashop-1.6 prestashop-1.5 prestashop-1.7

我正在尝试在 $this_select 中使用左连接添加以下查询,但无法正常工作

下面是我的工作查询,它​​工作正常:

  select      a.id_customer as id_customer,
        a.id_shop,
        a.email,
        a.lastname,
        a.firstname,
        max(c.date_add) as last_visit,
        IFNULL(max(b.date_add),'1001-01-01 00:00:00') as Last_order_date
 from        ps_customer a
 left join  ps_orders b
  on          a.id_customer = b.id_customer
 left join   ps_guest g 
 on          a.id_customer = g.id_customer
left join   ps_connections c
on          g.id_guest = c.id_guest
group by    a.id_customer
 having      to_days(Last_order_date) < to_days(now())- '30'

但我的问题是,当我在我的 Controller 中放置查询代码下方时,它没有采用第一个和第二个左连接:

    $this->_select='        
    a.id_shop,
    a.email,
    a.lastname,
    a.firstname,
    max(c.date_add) as last_visit,
    IFNULL(max(b.date_add),"'.$default_date.'") as Last_order_date
    ';

    $this->_join = '
    LEFT JOIN `'._DB_PREFIX_.'orders` b ON (a.`id_customer` =b.`id_customer`)';

    $this->_join ='left join   ps_guest g 
    on (a.id_customer = g.id_customer)';

    $this->_join ='left join   ps_connections c
    ON    (   g.id_guest = c.id_guest)      
    group by    a.id_customer
    having      to_days(Last_order_date) < to_days(now())- '.$dormant_filter_days.'';

我在上面的 $this_select 或 $this_join 中做错了吗? Bleow 是数据库异常,我得到的问题是我在这里没有看到我的前两个连接,即它没有采用前两个连接

enter image description here

最佳答案

您将在每次调用 $this->_join = 时覆盖 _join 值。您应该使用 $this->_join .= 进行第二次和最后一次连接。

$this->_select = '          
    a.id_shop,
    a.email,
    a.lastname,
    a.firstname,
    MAX(c.date_add) AS last_visit,
    IFNULL(MAX(b.date_add), "' . $default_date . '") AS Last_order_date';

$this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'orders` b
    ON (a.`id_customer` = b.`id_customer`)';

$this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'guest` g 
    ON (a.id_customer = g.id_customer)';

$this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'connections` c
    ON (g.id_guest = c.id_guest)';

$this->_group = 'GROUP BY a.id_customer';

$this->_having = 'HAVING TO_DAYS(Last_order_date) < TO_DAYS(NOW()) - ' . $dormant_filter_days;

关于mysql - prestashop 1.6 中具有过滤天数的休眠用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38435435/

相关文章:

mysql if 条件

php - Prestashop 1.7 无法显示自定义模块

mysql - 根据另一列的 MAX 从一列中选择 DISTINCT

mysql - 使用占位符选择第二行

ssh - GitLab CI 因 SSH 错误加载 key 无效格式而失败

php - Prestashop 1.6 中自定义模块的 URL 链接

php - 如何在 Prestashop 1.6 后台列出未分配地址的订单

css - 在 prestashop 中拆分畅销书和新品

mysql - 如何使用变量的值作为 R 中数组的名称