这是我的桌子
表 1:订单
id total order_date
1 200 2016-04-22
2 300 2016-04-22
表 2:order_products
id order product_id qty
1 1 1 2
2 1 2 1
3 2 2 2
4 2 1 2
我的结果应该是
tot_order total_amount prd_qty
2 500 7
我的查询是
SELECT COUNT(ddo.id) AS tot_order,
SUM(ddo.total) AS total_amount,
(SELECT SUM(dop.qty)
FROM order_products dop
WHERE dop.order=ddo.id) AS prd_qty
FROM orders ddo
WHERE DATE(ddo.`order_date`) BETWEEN '2016-04-22' AND '2016-04-22'
我可以获得total_order
和total_amount,但如何获得prd_qty
?
谢谢