There is a basic query that does a specific selection. And you need to attach another field to it. Here is what my query looks like now:
select m.PIPE_NUMBER, m.PIPE_YEAR, s.WC_INSTANCE, r.WORKCENTER_ID, s.RETURN_REASON, m.DIAMETER, m.THICKNESS, m.MELT_NUMBER, m.PART_WELD, m.STEELMARK, m.VENDER, s.WAREHOUSE_BEFORE_MOVING, s.ORDER_NUM_RES || '-' || s.ORDER_ITEM_RES as res_und_order, s.CREATE_DATE, s.INSERT_OPERATOR, (select min(p.CREATE_DATE) keep(dense_rank first order by s.create_date desc) from WC_7_3_SGP s left join WC_4_8_PRIEMKA p on s.SHOP_ID = p.SHOP_ID and s.PIPE_YEAR = p.PIPE_YEAR and s.PIPE_NUMBER = p.PIPE_NUMBER and p.EDIT_STATE = 0 and p.WC_INSTANCE = s.WC_INSTANCE where s.ORDER_NUM_RES is null and s.ORDER_ITEM_RES is null and s.EDIT_STATE = 0 and s.PIPE_NUMBER = m.PIPE_NUMBER) as DATE_CANCEL_RESERV, (select min(p.INSERT_OPERATOR) keep(dense_rank first order by s.create_date desc) from WC_7_3_SGP s left join WC_4_8_PRIEMKA p on s.SHOP_ID = p.SHOP_ID and s.PIPE_YEAR = p.PIPE_YEAR and s.PIPE_NUMBER = p.PIPE_NUMBER and p.EDIT_STATE = 0 and p.WC_INSTANCE = s.WC_INSTANCE where s.ORDER_NUM_RES is null and s.ORDER_ITEM_RES is null and s.EDIT_STATE = 0 and s.PIPE_NUMBER = m.PIPE_NUMBER) as OPERATOR_PRM from WC_MAIN m left join WC_1_2_LIST l on m.SHOP_ID = l.SHOP_ID and m.PIPE_YEAR = l.PIPE_YEAR and m.PIPE_NUMBER = l.PIPE_NUMBER left join WC_4_8_PRIEMKA p on m.SHOP_ID = p.SHOP_ID and m.PIPE_YEAR = p.PIPE_YEAR and m.PIPE_NUMBER = p.PIPE_NUMBER left join WC_7_3_SGP s on m.SHOP_ID = s.SHOP_ID and m.PIPE_YEAR = s.PIPE_YEAR and m.PIPE_NUMBER = s.PIPE_NUMBER left join ROUTE_PIPE_MOVES r on m.SHOP_ID = r.SHOP_ID and m.PIPE_YEAR = r.PIPE_YEAR and m.PIPE_NUMBER = r.PIPE_NUMBER where m.EDIT_STATE = 0 and p.EDIT_STATE = 0 and l.EDIT_STATE = 0 and s.EDIT_STATE = 0 and r.EDIT_STATE = 0 and r.ACTION = 'MOVE' To the main part of the request you need to attach a field on the following conditions using case:
If a
- the minimum date of the receiving point is greater than the maximum date of the shr point,
- Return address is null and
s.ORDER_NUM_RES||'-'|| s.ORDER_ITEM_RES = p.ORDER_NUMBER
then the field I need is created, say with the name status, and it is written “Confirmed”,
- otherwise: the same conditions only
s.ORDER_NUM_RES||'-'|| s.ORDER_ITEM_RES <> p.ORDER_NUMBERs.ORDER_NUM_RES||'-'|| s.ORDER_ITEM_RES <> p.ORDER_NUMBERno longer equal, then the field is “Not confirmed”, - otherwise, the field is spelled "Active."
I can not understand how to stick it among the fields. Either very complex nesting with cases, or I can not imagine.
select p.CREATE_DATE, s.CREATE_DATE, s.RETURN_ADDRESS, s.ORDER_NUM_RES || '-' || s.ORDER_ITEM_RES as res_und_order, p.ORDER_NUMBER from WC_MAIN m left join WC_4_8_PRIEMKA p on m.SHOP_ID = p.SHOP_ID and m.PIPE_YEAR = p.PIPE_YEAR and m.PIPE_NUMBER = p.PIPE_NUMBER left join WC_7_3_SGP s on m.SHOP_ID = s.SHOP_ID and m.PIPE_YEAR = s.PIPE_YEAR and m.PIPE_NUMBER = s.PIPE_NUMBER Here is a request for an example. Conditions remain the same as I described above. Dates are just p.CREATE_DATE and s.CREATE_DATE . s is the date of the first item, and p is the date of the second.