$query = "SELECT sum(o.feeship) feeship_total,
(SELECT SUM(p.products_price) FROM products p
left join orders_products op on op.products_id = p.products_id
WHERE op.orders_id = o.orders_id) AS cost
FROM orders o ";
$query .= " GROUP BY year(o.date_purchased), month(o.date_purchased)";
if ($sel_month<>0)
$query .= ", dayofmonth(o.date_purchased)";
$query .= " ORDER BY o.date_purchased";
用上面的SQL,只select sum products_price
对所有第一单的产品。如何将(sum products_price
所有订单产品的)总和跟随 order by group by
。它看起来像如何编写相同的 sql 来选择feeship_total
和sum(cost)
?