Oracle 製造費用Script
SELECT gc.segment1 "公司別",
gc.segment2 "主目",
gc.segment3 "子目",
gc.segment4 "節段四",
SUM(gb.period_net_cr - gb.period_net_dr) "金額"
FROM gl_balances gb,
gl_code_combinations gc
WHERE gb.code_combination_id = gc.code_combination_id
AND gb.set_of_books_id = 1
AND gb.period_name = TO_CHAR(TO_DATE('201801', 'YYYYMM'), 'Mon-YY')
AND gb.translated_flag IS NULL -- 作帳幣別
AND gc.account_type = 'R'
AND SUBSTRB(gc.segment3, 1, 1) = '6'
AND SUBSTRB(gc.segment3, 1, 2) NOT IN('62', '63') -- 費用類會科
--AND SUBSTRB(gc.segment3, 1, 1) = '7' -- 銷貨費用
GROUP BY gc.segment1,
gc.segment2,
gc.segment3,
gc.segment4
HAVING SUM(gb.period_net_cr - gb.period_net_dr) <> 0;