Our warehouse database contains an order_header table and an order_line table (1 to n).
Joins are on order/shipment number and type (S51 = order , S01 = shipment)
An ordernumber is unique in the header , for instance B123456. As soon as a shipment is established one or more (partial) shipmentnumbers are created in header:
B123456-1
B123456-2 etc.
Each shipmentnumber has 1 or more lines in the line table. The lines contain productcode and quantity. The products and quantities from the order-lines are the subject of the output of the query.
Query should produce the sum of the quantities per productcode for orders of a certain status. However if there exists a corresponding shipment of a certain status the order it relates to should not be taken into account when aggregating the quantities.
Problem 1: Orders and shipments are stored in the same tables, only the field ‘type’ and the prefix after the ordernumber indicates that it concerns a shipment.
Problem 2: There is no field in header table that contains the ordernumber (7 positions) for BOTH orders AND shipments, making an autojoin with header impossible.
(B123456 relates to B123456-1 , but how to join these ?)
So far I can only think of a solution by creating a view that contains the shipments with an extra field (a substring of first 7 positions of shipmentnumber) to make a join to the orderheader, but since the database (ORACLE 7.3.4) is bought with the application , this is a bit tricky.
Can anyone think of a single SQL , PL/SQL that can do the trick?
T. Blom
Information analist
Shimano Europe
tbl@shimano-eu.com
Joins are on order/shipment number and type (S51 = order , S01 = shipment)
An ordernumber is unique in the header , for instance B123456. As soon as a shipment is established one or more (partial) shipmentnumbers are created in header:
B123456-1
B123456-2 etc.
Each shipmentnumber has 1 or more lines in the line table. The lines contain productcode and quantity. The products and quantities from the order-lines are the subject of the output of the query.
Query should produce the sum of the quantities per productcode for orders of a certain status. However if there exists a corresponding shipment of a certain status the order it relates to should not be taken into account when aggregating the quantities.
Problem 1: Orders and shipments are stored in the same tables, only the field ‘type’ and the prefix after the ordernumber indicates that it concerns a shipment.
Problem 2: There is no field in header table that contains the ordernumber (7 positions) for BOTH orders AND shipments, making an autojoin with header impossible.
(B123456 relates to B123456-1 , but how to join these ?)
So far I can only think of a solution by creating a view that contains the shipments with an extra field (a substring of first 7 positions of shipmentnumber) to make a join to the orderheader, but since the database (ORACLE 7.3.4) is bought with the application , this is a bit tricky.
Can anyone think of a single SQL , PL/SQL that can do the trick?
T. Blom
Information analist
Shimano Europe
tbl@shimano-eu.com