ไว้หาความแตกต่างของ 2 table หรือ 2 query ที่มี column ที่นำมาเปรียบเทียบจำนวนเท่ากัน
syntax
select field1, field2, . field_n
from tables
MINUS
select field1, field2, . field_n
from tables;
The following is an MINUS query that uses an ORDER BY clause:
select supplier_id, supplier_name
from suppliers
where supplier_id > 2000
MINUS
select company_id, company_name
from companies
where company_id > 1000
ORDER BY 2;
select * from
(select budget_id, BG_FWD_RS_AMT,div_code -- FWD_RS_BL_AMT,/*FWD_BL_AMT,*/ BG_FWD_AMT--, BUDGET_AMT-USE_AMT USE_AMT
from bg_proj_exp_rev_yearly
where budget_year_control = 2554
--and div_code = '302'
--and (atv_code not like 'ผ%' and atv_code not like 'ผ?9%')
--and budget_id = '1'
and atv_code not like 'ผ9%'
minus
select a.budget_id, sum(a.BG_FRW_BAL), c.div_code--,/*SUM(NVL(a.FRW_BAL,0)), SUM(NVL(a.FW_BAL,0)),*/ sum(a.BG_FW_BAL)--, sum(a.BG_USAGE_BAL)
from bg_budget_movement a
, bg_proj_exp_rev_yearly c
where a.budget_year_control = 2554
and a.seq = (select max(seq)
from bg_budget_movement b
where a.ou_code = b.ou_code
and a.budget_year_control = b.budget_year_control
and a.budget_id = b.budget_id)
and a.budget_year_control = 2554
and a.ou_code = c.ou_code
and a.budget_year_control = c.budget_year_control
and a.budget_id = c.budget_id
--and c.div_code = '302'
--and (c.atv_code not like 'ผ%' and c.atv_code not like 'ผ9%')
and atv_code not like 'ผ9%'
--and a.budget_id = '1'
group by a.budget_id, c.div_code)
--where budget_id = '1226'
ไม่มีความคิดเห็น:
แสดงความคิดเห็น