I have the following query:
For one particular order, the result says qty 2.5 but it should be 5.
If I use SUM I get 15, AVG gives 2.5.
So I removed grouping and got the following (edited) result:
So you can see where it gets the AVG and SUM results.
But how can I get 5?!
Thanks
There's no need for sarcastic replies, we've not all been this sad for that long!
Code:
SELECT
ro.work_center_no Work_Centre,
wc.description Work_Centre_Description,
ith2.order_no Shop_Order,
ith2.part_no Part_No,
ip.description Part_Number_Description,
sum(ith2.quantity) Quantity,
to_char(avg(soo.labor_setup_time * soo.crew_size),999999.9999) Setup_Time,
to_char(avg(soo.labor_run_factor * soo.crew_size),999999.9999) Labor_Time,
to_char(avg(soo.labor_run_factor * soo.crew_size * ith2.quantity),999999.9999) Total_Labor_Run_Time,
to_char(avg(soo.labor_run_factor * soo.crew_size * ith2.quantity) + avg(soo.labor_setup_time * soo.crew_size),999999.9999) Total_Hours_Executed
FROM
ifsapp.inventory_transaction_hist2 ith2,
ifsapp.routing_operation ro,
ifsapp.shop_order_operation soo,
ifsapp.inventory_part ip,
ifsapp.work_center wc
WHERE
ith2.transaction_code='OOREC' and
ith2.part_no=ro.part_no and
ith2.part_no=ip.part_no and
ith2.order_no = soo.order_no and
ro.work_center_no=&work_centre and
ro.work_center_no=wc.work_center_no and
soo.work_center_no=ro.work_center_no and
ith2.dated between to_date('&Start_Date','DD/MM/YYYY') and to_date('&End_Date','DD/MM/YYYY')
GROUP BY
ro.work_center_no,
ith2.order_no,
ith2.part_no,
ip.description,
wc.description
ORDER BY
ro.work_center_no,
lpad(ith2.order_no,20,'0'),
lpad(ith2.part_no,30,'0')
For one particular order, the result says qty 2.5 but it should be 5.
If I use SUM I get 15, AVG gives 2.5.
So I removed grouping and got the following (edited) result:
Code:
Work Centre Shop Order Part No Quantity Setup Time Labor Time Total Labor Run Time Total Hours Executed
127 3842 7500499 4 0 2 8 8
127 3842 7500499 4 0 2 8 8
127 3842 7500499 4 0 2 8 8
127 3842 7500499 1 0 2 2 2
127 3842 7500499 1 0 2 2 2
127 3842 7500499 1 0 2 2 2
So you can see where it gets the AVG and SUM results.
But how can I get 5?!
Thanks
There's no need for sarcastic replies, we've not all been this sad for that long!