WORK_DATE | LINE_ID | MODEL_ID | SHIFT | WC_TYPE | LOT_ID | LOT_TYPE | IN_QTY | OUT_QTY | LOSS_CODE | LOSS_QTY |
20110510 | X30 | XPB | 1 | D | XPBKE023 | 0 | 2440 | 2420 | 104 | 5 |
20110510 | X30 | XPB | 1 | D | XPBKE023 | 0 | 2440 | 2420 | 112 | 2 |
20110510 | X30 | XPB | 1 | D | XPBKE023 | 0 | 2440 | 2420 | 201 | 7 |
20110510 | X30 | XPB | 1 | D | XPBKE023 | 0 | 2440 | 2420 | 404 | 6 |
20110510 | X30 | XPB | 1 | D | XPBKE033 | 0 | 3170 | 3148 | 112 | 3 |
20110510 | X30 | XPB | 1 | D | XPBKE033 | 0 | 3170 | 3148 | 201 | 7 |
20110510 | X30 | XPB | 1 | D | XPBKE033 | 0 | 3170 | 3148 | 404 | 12 |
20110510 | X30 | XPB | 2 | D | XPBKE033 | 0 | 6382 | 6350 | 104 | 3 |
20110510 | X30 | XPB | 2 | D | XPBKE033 | 0 | 6382 | 6350 | 112 | 3 |
20110510 | X30 | XPB | 2 | D | XPBKE033 | 0 | 6382 | 6350 | 116 | 1 |
20110510 | X30 | XPB | 2 | D | XPBKE033 | 0 | 6382 | 6350 | 201 | 7 |
20110510 | X30 | XPB | 2 | D | XPBKE033 | 0 | 6382 | 6350 | 404 | 18 |
SELECT a.WORK_DATE
, NVL(SUM(a.IN_QTY), 0) AS INPUT_VAL
, DECODE(NVL(SUM(a.IN_QTY), 0), 0, 0, NVL(SUM(b.LOSS_QTY), 0) / SUM(a.IN_QTY)) AS P_VAL
FROM(
SELECT work_date, lot_id, shift,in_qty, NVL(loss_qty,0) FROM WC_WORKLOG_DETAIL WHERE work_date ='20110510' AND model_id = 'XPB' AND wc_type = 'D' AND substr(lot_id,8,1) = '3'-- AND loss_code = '104'
GROUP BY work_date, lot_id, shift, in_qty,loss_qty -- ,loss_code, loss_qty
) a,
(
SELECT work_date, lot_id, shift, in_qty, loss_qty FROM WC_WORKLOG_DETAIL WHERE work_date ='20110510' AND model_id = 'XPB' AND wc_type = 'D' AND substr(lot_id,8,1) = '3' AND loss_code = '104'
GROUP BY work_date, lot_id, shift, in_qty ,loss_qty -- ,loss_code, loss_qty
) b
GROUP BY a.WORK_DATE
이렇게 해도 11992가 안되고;;;;
SELECT WORK_DATE
, NVL(SUM(IN_QTY), 0) AS INPUT_VAL
, DECODE(NVL(SUM(IN_QTY), 0), 0, 0, NVL(SUM(LOSS_QTY), 0) / SUM(IN_QTY)) AS P_VAL
FROM(
SELECT WORK_DATE, IN_QTY
,SUM( LOSS_QTY) AS LOSS_QTY
FROM WC_WORKLOG_DETAIL
where MODEL_ID = 'XPB'
and WC_TYPE = 'D'
--and LOSS_CODE = '104'
--and LOT_TYPE = '0'
and WORK_DATE >= '20110510'
and WORK_DATE <='20110510'
and 1=1
GROUP BY WORK_DATE, IN_QTY, SHIFT
)
where 1=1
--and IN_QTY > TO_NUMBER(@I_MINVALUE)
and 1=1
GROUP BY WORK_DATE
이렇게 해도 안되고;;;
loss_code는 조건으로 들어가더라도 in_qty는 항상 11992가 나와야 하는데;;;어떻게 하면 좋을까요?ㅠㅠ
부탁드립니다.ㅠㅠ
꼬옥꼬옥좀 봐주세요.ㅠㅠ