Prestashop:致命错误:未捕获的子查询返回超过1行

时间:2016-08-30 06:26:13

标签: php mysql prestashop prestashop-1.6 prestashop-1.7

当我在MySQL服务器中执行此操作时,以下查询工作正常,但在Prestashop中运行时显示错误&sub-query返回多行'用粗体标出。

$sql='SELECT g.`id_group`,gl.`name`,oh.`date_add`,o.`id_order`,o.`invoice_number`,FORMAT(o.`total_paid`,2) AS total_paid,osl.`name` AS order_status,o.`credit_days`,DATEDIFF(DATE_ADD((**SELECT oha.`date_add` FROM '._DB_PREFIX_.'order_history oha WHERE  o.`id_order` = oha.`id_order` AND oha.`id_order_state`=40**) ,INTERVAL o.`credit_days` DAY),NOW()) AS aging

            FROM '._DB_PREFIX_.'orders o

            LEFT JOIN '._DB_PREFIX_.'order_history oh ON (o.`id_order` = oh.`id_order`)

            LEFT JOIN '._DB_PREFIX_.'order_state_lang osl ON (osl.`id_order_state` = oh.`id_order_state`)

            LEFT JOIN '._DB_PREFIX_.'customer c ON(c.`id_customer` = o.`id_customer`)

            LEFT JOIN '._DB_PREFIX_.'group g ON(g.`id_group`=c.`id_default_group`)

            LEFT JOIN '._DB_PREFIX_.'group_lang gl ON(gl.`id_group`=g.`id_group`)   

            WHERE 

            oh.id_Order_history IN (

            SELECT  MAX(oha.`id_order_history`) FROM '._DB_PREFIX_.'order_history AS oha

            WHERE o.id_order = oha.id_order GROUP BY oha.id_order
            )

            AND oh.`id_order_state` IN (35,37,39)
            AND gl.`id_lang`=1
            AND osl.`id_lang`=1';

    if($id_group)       
    {
        $sql .=" AND g.`id_group`=".$id_group;
    }

    if($from & $to)     
    {
        $to.=" 23:59:59";
        $sql .=" AND oh.`date_add` BETWEEN '".$from."' AND '".$to."'";
    }   

    $result=Db::getInstance()->ExecuteS($sql);  

0 个答案:

没有答案