MySQL附加所有列值

时间:2016-07-27 13:01:44

标签: mysql sql

我有一个名为material_line_item的表格,在该表格中有3列1.item_master_id 2.received_quantity3.ordered_quantity我想要一个查询来计算这两个字段中的所有数量(received_quantity` and `ordered_quantity)基于item_master_id

**Screen Snap for this**

2 个答案:

答案 0 :(得分:4)

这应该有所帮助:

SELECT item_master_id, sum(received_quantity), sum(ordered_quantity) FROM material_line_item
GROUP BY item_master_id

答案 1 :(得分:1)

与上述解决方案相同,但已格式化:)

  

SELECT item_master_id ,Sum(received_quantity) Total_Received_Qty ,Sum(ordered_quantity) Total_Ordered_Qty FROM material_line_item GROUP BY item_master_id