Sortere ud med en ekstra WHERE
Hejsa,Jeg har en Prestashop løsning, hvor jeg prøver at rette en rapport til som bruger denne kode:
$this->query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name,
ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold,
IFNULL(stock.quantity, 0) as quantity,
IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold,
ROUND(IFNULL(IFNULL(SUM(od.product_quantity), 0) / (1 + LEAST(TO_DAYS('.$array_date_between[1].'), TO_DAYS(NOW())) - GREATEST(TO_DAYS('.$array_date_between[0].'), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold,
ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold,
(
SELECT IFNULL(SUM(pv.counter), 0)
FROM '._DB_PREFIX_.'page pa
LEFT JOIN '._DB_PREFIX_.'page_viewed pv ON pa.id_page = pv.id_page
LEFT JOIN '._DB_PREFIX_.'date_range dr ON pv.id_date_range = dr.id_date_range
WHERE pa.id_object = p.id_product AND pa.id_page_type = ('.(int)Page::getPageTypeByName('product').')
AND dr.time_start BETWEEN '.$date_between.'
AND dr.time_end BETWEEN '.$date_between.'
) AS totalPageViewed
FROM '._DB_PREFIX_.'product p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->getLang().Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'order_detail od ON od.product_id = p.id_product
LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order
'.Product::sqlStock('p', 0).'
WHERE product_shop.active = 1
AND o.valid = 1
AND o.invoice_date BETWEEN '.$date_between.'
GROUP BY od.product_id';
Jeg ville gerne føje en ekstra WHERE sætning til koden, men kan ikke få det til at fungere.
Det drejer som om feltet "id_supplier" i tabellen PRODUCT, og har prøvet med dette: AND product.id_supplier = 3
men det virker ikke... hvordan skal det gøre ?