合并2表和ID

时间:2018-04-13 12:23:23

标签: php sql prestashop

我正在尝试根据这两个表中的ID收集2个表,表[2]的数据将进入表[0],这要归功于它们共有的id和第2个板的ditto 。这就是我已经做过的事情:

Array

$sql1 = Db::getInstance()->executeS('
            SELECT ra.id_customer, c.firstname AS Prénom, c.lastname AS Nom, COUNT(DISTINCT(rs.id_customer)) AS NbFilleuls, SUM(o.total_products_wt + o.total_shipping) AS CA
            FROM ' . _DB_PREFIX_ . 'customer c
            LEFT JOIN ' . _DB_PREFIX_ . 'rewards_account ra ON(c.id_customer = ra.id_customer)
            LEFT JOIN ' . _DB_PREFIX_ . 'rewards_sponsorship rs ON(ra.id_customer = rs.id_sponsor)
            LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON(rs.id_customer = o.id_customer)
            WHERE ra.remind_active = 1
            GROUP BY rs.id_sponsor');

            $sql2 = Db::getInstance()->executeS('
            SELECT ra.id_customer, SUM(o.total_products_wt + o.total_shipping) AS CA_DATE
            FROM ' . _DB_PREFIX_ . 'customer c
            LEFT JOIN ' . _DB_PREFIX_ . 'rewards_account ra ON(c.id_customer = ra.id_customer)
            LEFT JOIN ' . _DB_PREFIX_ . 'rewards_sponsorship rs ON(ra.id_customer = rs.id_sponsor)
            LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON(rs.id_customer = o.id_customer)
            WHERE o.date_add >= \'2018-04-09 00:00:00\'
            AND o.date_add <= \'2018-04-13 00:00:00\'
            GROUP BY rs.id_customer');

            $result = array_merge($sql1, $sql2);

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

试试这个:

$results = array();
for ($i = 0 ; $i <count($sql1) ; i++)
{
    $results[i] = array_merge($sql1[i],$sql2[i]);
}

你想要合并两个数组中的特定单元格,而不是自己的数组(如果我理解你的问题)。

另外,我假设$ sql1和$ sql2在具有相同索引的单元格中具有相同的长度和[id_customer]匹配。

答案 1 :(得分:0)

另一方面,如果一个人没有与他们看起来没有看到附件的日期相比有营业额,那么它就起作用了:

enter image description here

无论如何我想张贴

由于