我有一个如下查询:
结果给出@sold_count:=SUM(I.quantity) = 10,但@sold_count = 0,
所以计算都是0。
这里应该有什么问题?
SET @sold_count :=0;
SELECT
@sold_count:=SUM(I.quantity),
@sold_count,I.from_widget,COUNT(from_widget) as order_count,
(@sold_count * buy_price) as ciro,
(@sold_count * list_price) as liste_ciro,
(@sold_count * widget_price) as vitrin_ciro,
P.*
FROM
tbl_products P
LEFT JOIN tbl_order_items I on I.product_id = P.id
WHERE
P.publish_date BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )
GROUP BY I.from_widget,I.product_id
ORDER BY publish_date DESC