Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用默认值优化多个表上的查询_Php_Mysql_Sql_Oscommerce - Fatal编程技术网

Php 使用默认值优化多个表上的查询

Php 使用默认值优化多个表上的查询,php,mysql,sql,oscommerce,Php,Mysql,Sql,Oscommerce,我正在尝试使用Recover Cart Sales贡献在一个旧的osCommerce站点上优化一些非常慢的查询 我试图从Cart和customers表中提取信息,我可以很容易地做到这一点。诀窍是我需要弄清楚他们最后一次被联系是什么时候,而不必再做另一个查询。它存在于另一个表中,如果我们以前从未联系过他们,那么表中没有enty,因此它应该为null 这就是我所拥有的,它的工作原理是,它只在scart表中有一个条目时才提取数据 SELECT DISTINCT cb.customers_id, c.c

我正在尝试使用Recover Cart Sales贡献在一个旧的osCommerce站点上优化一些非常慢的查询

我试图从Cart和customers表中提取信息,我可以很容易地做到这一点。诀窍是我需要弄清楚他们最后一次被联系是什么时候,而不必再做另一个查询。它存在于另一个表中,如果我们以前从未联系过他们,那么表中没有enty,因此它应该为null

这就是我所拥有的,它的工作原理是,它只在scart表中有一个条目时才提取数据

SELECT DISTINCT cb.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address, sc.datemodified AS last_contacted
    FROM customers_basket cb, customers c, scart sc
        WHERE c.customers_id = cb.customers_id
            AND cb.customers_id = sc.customers_id 
            AND cb.customers_basket_date_added < 20130916 
            AND cb.customers_basket_date_added > 20130101
        AND cb.customers_id NOT IN(SELECT sc.customers_id  //Excludes people we've contacted in the last month
                                FROM scart sc
                        WHERE sc.datemodified >20130816)
    ORDER BY cb.customers_id DESC

听起来你需要左键连接?如果存在,它将返回您感兴趣的行;如果不存在,它将返回NULL

SELECT DISTINCT cb.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address, sc.datemodified AS last_contacted
FROM customers_basket cb 
INNER JOIN customers c ON c.customers_id = cb.customers_id
LEFT JOIN scart sc ON cb.customers_id = sc.customers_id
WHERE cb.customers_basket_date_added < 20130916 
  AND cb.customers_basket_date_added > 20130101
  AND cb.customers_id NOT IN(SELECT sc.customers_id  //Excludes people we've contacted in the last month
                            FROM scart sc
                    WHERE sc.datemodified >20130816)
ORDER BY cb.customers_id DESC

完美的我的连接很糟糕!谢谢