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, 2) NOT IN('62', '63') -- 費用類會科
GROUP BY gc.segment1,
gc.segment2,
gc.segment3,
gc.segment4
HAVING SUM(gb.period_net_cr - gb.period_net_dr) <> 0;