SQL太長,只貼出大概結構
select ohdr.order_number
, oline.line_number || '.' || oline.shipment_number line_number
, asgn.delivery_id
,(
select
sum(wdd.requested_quantity)
from oe_order_headers_all oh,
oe_order_lines_all ol,
wsh_delivery_details wdd,
wsh_delivery_assignments wda,
wsh_new_deliveries wnd
where oh.org_id = ol.org_id
and oh.header_id = ol.header_id
and ol.line_id = wdd.source_line_id
and wdd.DELIVERY_DETAIL_ID = wda.DELIVERY_DETAIL_ID
and wda.DELIVERY_ID = wnd.DELIVERY_ID
and oh.order_number = ohdr.order_number
and ol.line_number = oline.line_number
and ol.shipment_number = oline.shipment_number
and wdd.LOT_NUMBER = ddet.LOT_NUMBER
group by oh.order_number,
ol.line_number,
ol.shipment_number,
wnd.name,
wdd.LOT_NUMBER
)qty_by_job
........
FROM wsh_delivery_details ddet
, (SELECT l.*
, NVL (m1.inventory_item_id, l.inventory_item_id) item_id
FROM oe_order_lines l
, mtl_system_items_b m1
WHERE l.customer_job = m1.segment1(+)
AND l.ship_from_org_id = m1.organization_id(+)) oline
, oe_order_headers ohdr
.............. /* 還有其它表,不一一列出,只列和子查詢關聯到的*/
GROUP BY ......... /* from 中用到的全部欄位*/
對REQUESTED_QUANTITY求和,按結果顯示在QTY_BY_JOB
以LOT_NUMBER=6069749為例,總共有兩行,LINE_NUMBER分別是2.2,2.1
LINE_NUMBER是2.2時,REQUESTED_QUANTITY有兩行(excel的第4,5行),分別是966,34,將這兩個數求和結果1000,
excel的第4,5行都顯示了1000,但我希望excel的第4行才顯示1000,第5行為空
LINE_NUMBER是2.1時,REQUESTED_QUANTITY有兩行(excel的第6,7行,分別是1888,320),將這兩個數求和結果2208,
excel的第6,7行都顯示了2208,但我希望excel的第6行才顯示2208,第7行為空
上圖是查詢結果,下圖是期望結果
uj5u.com熱心網友回復:
哪位大神幫幫忙啊uj5u.com熱心網友回復:
哪位大神幫幫忙啊uj5u.com熱心網友回復:
陳述句太長不看。只看你下邊的那兩個圖,decode(row_number() over(partition by lot_number order by requested_quantity desc), 1, qty_by_job, null)
uj5u.com熱心網友回復:
這個函式好像是可以達到你效果要的結果 你去百度搜索下這個函式的詳細用法應該是可以的。。你圖中的意思有點沒明白,兩行都是2208和1000 但是你想要的結果是確實一個值的總和 是想要取QUANTITY最大值的那個和嗎?轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/53993.html
標籤:開發
