SELECT `products`.*, SUM(orders.total_count) AS revenue, SUM(orders.quantity) AS qty FROM `products`
LEFT JOIN `orders` ON (`products`.`id` = `orders`.`product_id`)
WHERE (`orders`.`status` = 'delivered' OR `orders`.`status` = 'new')
GROUP BY `products`.`ID` ORDER BY products.ID DESC LIMIT 10 OFFSET 0
这就是我得到的。目前它只抓取具有已交付或新订单的产品。
该 WHERE 语句仅用于正确计算 SUM(orders.total_count) 和 SUM(orders.quantity) -
我想抢所有的产品,如果有这个产品的订单,那么它应该查看 where 声明,以确保我们抢的订单是新的或已交付的。