下面的查询当前将总计显示为逐项,但我想要的是计算采购订单中所有项目的小计。
谢谢
输出应该是:
POID Item ItemQTY ItemPrice ItemTotal SubTotal
1 A 1 15.00 15.00 80.50
1 B 1 25.50 25.50 80.50
1 C 2 20.00 40.00 80.50
2 X 6 5.00 30.00 50.00
2 Y 2 10.00 20.00 50.00
关系:purchase_order 1 - N purchase_order_items
SELECT
purchase_order.id AS POID,
purchase_order_items.description AS Item,
purchase_order_items.quantity AS ItemQTY,
purchase_order_items.price AS ItemPrice,
(purchase_order_items.quantity*purchase_order_items.price) AS ItemTotal
/* Here, Subtotal should be calculated and displayed */
FROM purchase_order
INNER JOIN purchase_order_items ON purchase_order.id = purchase_order_items.fk_purchase_order
我查看了MySQL 查找小计和小计和 SQL,但无法应用于我的查询。