马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
我现在按照wip值报表写sql,用于核对外协加工,物料差异,估计废料差异三样的在06-8月的差异
我发现加了gl_code_combinations gcc
与m3表后数据大量重复,哪位高手帮忙看一下吧!在线急等ing...
select DISTINCT wpb.class_type,
wdj.class_code,
we.wip_entity_name,
oap.schedule_close_date,
wdj.scheduled_start_date,
wpb.acct_period_id,
sum(round(1 * (decode(m3.lookup_code,
1,
nvl(wpb.pl_material_in, 0),
2,
nvl(wpb.pl_material_overhead_in, 0),
3,
nvl(wpb.tl_resource_in, 0) +
nvl(wpb.pl_resource_in, 0),
4,
nvl(wpb.tl_outside_processing_in, 0) +
nvl(wpb.pl_outside_processing_in, 0),
5,
nvl(wpb.tl_overhead_in, 0) +
nvl(wpb.pl_overhead_in, 0),
12,
nvl(wpb.tl_scrap_in, 0),
0)),
2)) Costs_Incurred,
sum(round(1 * (decode(m3.lookup_code,
1,
nvl(wpb.tl_material_out, 0) +
nvl(wpb.pl_material_out, 0),
2,
nvl(wpb.pl_material_overhead_out, 0) +
nvl(wpb.tl_material_overhead_out, 0),
3,
nvl(wpb.tl_resource_out, 0) +
nvl(wpb.pl_resource_out, 0),
4,
nvl(wpb.tl_outside_processing_out, 0) +
nvl(wpb.pl_outside_processing_out, 0),
5,
nvl(wpb.tl_overhead_out, 0) +
nvl(wpb.pl_overhead_out, 0),
12,
nvl(wpb.tl_scrap_out, 0),
0)),
2)) Costs_Relieved,
sum(round(1 * (decode(m3.lookup_code,
1,
nvl(wpb.tl_material_var, 0) +
nvl(wpb.pl_material_var, 0),
2,
nvl(wpb.pl_material_overhead_var, 0) +
nvl(wpb.tl_material_overhead_var, 0),
3,
nvl(wpb.tl_resource_var, 0) +
nvl(wpb.pl_resource_var, 0),
4,
nvl(wpb.tl_outside_processing_var, 0) +
nvl(wpb.pl_outside_processing_var, 0),
5,
nvl(wpb.tl_overhead_var, 0) +
nvl(wpb.pl_overhead_var, 0),
12,
nvl(wpb.tl_scrap_var, 0),
0)),
2)) Elemental_Var,
ml.meaning,
M2.MEANING,
M3.meaning
from wip_entities we,
mfg_lookups ml,
mfg_lookups m2,
mfg_lookups m3,
mtl_system_items msi,
wip_period_balances wpb,
wip_discrete_jobs wdj,
org_acct_periods oap,
gl_code_combinations gcc
where wdj.organization_id = 84
and wpb.wip_entity_id = wdj.wip_entity_id
and wpb.organization_id = 84
and ml.lookup_type = 'WIP_CLASS_TYPE'
and ml.lookup_code = wpb.class_type
and oap.organization_id = 84
AND OAP.period_name = 'AUG-06'
and oap.acct_period_id = wpb.acct_period_id
and we.wip_entity_id = wdj.wip_entity_id
and we.organization_id = 84
and msi.inventory_item_id(+) = wdj.primary_item_id
and msi.organization_id(+) = 84
AND m2.LOOKUP_TYPE = 'WIP_JOB_STATUS'
and m2.LOOKUP_CODE = wdj.status_type
and m3.lookup_type = 'WIP_ELEMENT_VAR_TYPE'
-- and (m3.lookup_code in (4, 6, 12, 13)) --外协加工,物料差异,估计废料差异,
and gcc.chart_of_accounts_id =
(SELECT CHART_OF_ACCOUNTS_ID
FROM ORG_ORGANIZATION_DEFINITIONS
WHERE ORGANIZATION_ID = 84) --取科目
and gcc.code_combination_id = decode(m3.lookup_code,
1,
wdj.material_account,
2,
wdj.material_overhead_account,
3,
wdj.resource_account,
4,
wdj.outside_processing_account,
5,
wdj.overhead_account,
6,
wdj.material_variance_account,
7,
wdj.resource_variance_account,
8,
wdj.outside_proc_variance_account,
9,
wdj.overhead_variance_account,
12,
wdj.est_scrap_account,
13,
wdj.est_scrap_var_account,
0) |