我有一张表记录了公司内的发票。我需要确定特定发票号是否有多个条目,如果有,那么我需要查看箱位置。我需要将结果看作一个单一的发票条目,其中所有的数量,税额,成本价值和折现值总和在一起。最终输出应该只为每张发票显示一行,所有值汇总在一起。
Invoice | QtyInvoiced | TaxValue | CostValue | DiscValue | Warehouse | Bin
___________________________________________________________________________
1 1000 5.0 5.0 1.0 KT 23
1 500 5.0 5.0 1.0 KT Stage
2 1000 3.0 9.0 0.0 KT Stage
3 1000 5.0 5.0 1.0 KT 19
3 500 5.0 5.0 1.0 KT Stage
结果必须是:
Invoice | QtyInvoiced | TaxValue | CostValue | DiscValue | Warehouse | Bin
___________________________________________________________________________
1 1500 10.0 10.0 2.0 KT
2 1000 3.0 9.0 0.0 KT
3 1500 10.0 10.0 2.0 KT
答案 0 :(得分:0)
这应该得到你想要的东西,你可能需要稍微修改它以适应你没有真正提供表格结构。
SELECT invoice_nbr, SUM(qty) As TotalQty,
SUM(taxvalue) As TotalTaxValue,
SUM(costvalue) As TotalCostValue,
SUM(discvalue) As TotalDiscValue
FROM invoices
GROUP BY invoice_nbr
ORDER BY invoice_nbr;