/* Formatted on 2011/04/21 14:16 (Formatter Plus v4.8.8) */
SELECT plant, apa07, YEAR (apa12) years, TO_CHAR (apa12,
'yyyy/mm/dd') apa12,
apa12 cdate, apa13, SUM (x2 + x1 - x3) ans
FROM (SELECT 'ds01' plant, apa00, apa06,
NVL (pmc909, NVL (apa07, '無名稱')) apa07, apa12, apa13,
apa34f,
NVL (DECODE (SUBSTR (apa00, 1, 1), '2', apa34f * (-1)),
0) x1,
NVL (DECODE (SUBSTR (apa00, 1, 1), '1', apa34f), 0) x2,
NVL (DECODE (SUBSTR (apa00, 1, 1), '1', apa35f), 0) x3,
apa35f, pmc082
FROM ds.apa_file, ds.pmc_file
WHERE apa42 = 'N'
AND pmc01 = apa06
AND apa36 NOT IN ('12', '18')
AND SUBSTR (apa06, 1, 1) <> 'E'
AND SUBSTR (apa06, 1, 2) <> '3D'
AND apa34f > (apa35f + apa20))
WHERE apa13 IN ('NTD')
AND apa12 >= TO_DATE ('2011/04/21', 'yyyy/mm/dd')
AND apa12 <= TO_DATE ('2011/04/21', 'yyyy/mm/dd')
GROUP BY plant, apa07, apa12, apa13
HAVING SUM (x2 + x1 - x3) <> 0
ORDER BY 5, 2
全站熱搜