我正在尝试在我的sql语句中添加sum函数。目前我正在使用Oracle 12G; 我的select语句如下
select Distinct o.id as ID, o.orderno as "order", a.itemno as "Item Number",
od.total_qty_ord/a.pallet_ptsper as "Total Pallets" From Orders o, ord_detail od,
arinvt a
where o.id = od.orders_id (+) and a.id (+) = od.arinvt_id and o.orderno = '1323-PASO'
order by ID
目前,当我运行此商品时,如果我的销售订单有两个不同的订单项,我会收到两条不同的记录。我想能够总结我的脚本的“总托盘”部分。这可能吗?
答案 0 :(得分:1)
所选的o.id是否也必须在de group by子句中输入?我想是的。
select Distinct o.id as ID,
o.orderno as "order",
a.itemno as "Item Number",
sum(od.total_qty_ord/a.pallet_ptsper) as "Total Pallets"
From Orders o,
ord_detail od,
arinvt a
where o.id = od.orders_id (+)
and a.id (+) = od.arinvt_id
and o.orderno = '1323-PASO'
group by o.order, a.itemno, o.id ---> include the o.id
order by ID