高级成本查账的SQL语句

发布 2021-05-02 03:26:28 阅读 2699

第一部分:确保成本归属是否正确;

第一步:确认所有的领料单的领料成本是否算到成本计算单中;

1、查询【成本计算单】中本期下阶投入的成本汇总;

select ti006 as 工单单别,sum(tj012) as 本期下阶投入成本。

from acmtj left join acmti on tj001=ti001 and tj002=ti002

where ti003='201108'

group by ti006

order by ti006

2、查询领料的投入的成本。

select te011,sum(la013*la005*-1)

from mocte left join moctc on tc001=te001 and tc002=te002

left join invla on te001=la006 and te002=la007 and te003=la008

left join cmsmc on te008=mc001 and mc004='1'

left join cstta on te011=ta003 and te012=ta004 and te015=ta001 and ta002='201108'

where tc009='y' and te016 in ('1','3') and tc003>='20110801' and tc003<='20110831'

group by te011 order by te011

3、对比出来差异,如果哪个有差异,那么再明细到下面的单别单号去查询差异;

第二步:确认本期本阶投入人工/制费和【部门人工制费统计表】中是否有差异;还要确认本期投入的加工成本是否和【**商加工明细表】的加工金额相等;

1、查询本期本阶投入的人工/制费用金额;

select md003 as 人工制费,sum(tj011) as 本期本阶投入成本。

from acmtj left join acmti on tj001=ti001 and tj002=ti002 left join acmmd on tj003=md001

where ti003='201108' and md003 in ('2','4')

group by md003

order by md003

查询本期本阶投入的加工金额;

select md003 as 人工制费,sum(tj011) as 本期本阶投入成本。

from acmtj left join acmti on tj001=ti001 and tj002=ti002 left join acmmd on tj003=md001

where ti003='201108' and md003='3'

group by md003

order by md003

2、查询【部门人工制费统计表】中的人工制费的金额/【**商加工明细表】;

3、对比查出来的数据差异,确认本期投入的人工或制费或加工是否存在问题;

第三步:确认转出成本和入库成本是否存在差异;

1、查询【成本计算单】中的本期转出成本;

select ti006 as 工单单别,sum(tj019) as 本期转出成本。

from acmtj left join acmti on tj001=ti001 and tj002=ti002 left join acmmd on tj003=md001

where ti003='201108'

group by ti006

order by ti006

2、查询入库单/委外进货/委外退货的入库成本;

入库单查询。

select tg014,sum(la013*la005) as 成本金额。

from moctg

left join moctf on tf001=tg001 and tf002=tg002

left join invla on tg001=la006 and tg002=la007 and tg003=la008

left join cmsmc on tg010=mc001 and mc004='1'

left join cstta on tg014=ta003 and tg015=ta004 and ta001=la001 and ta002='201108'

where tf006='y' and tf003>='20110801' and tf003<='20110831'

group by tg014 order by tg014

-委外进。select ti013,sum(la013*la005) as 成本金额from mocti

left join mocth on th001=ti001 and th002=ti002

left join invla on ti001=la006 and ti002=la007 and ti003=la008

left join cmsmc on ti009=mc001 and mc004='1'

left join cstta on ti013=ta003 and ti014=ta004 and ta001=la001 and ta002='201108'

where th023='y' and th003>='20110801' and th003<='20110831'

group by ti013 order by ti013

-委外退。select tl015,sum(la013*la005) as 成本金额from moctk

left join moctl on tk001=tl001 and tk002=tl002

left join invla on tl001=la006 and tl002=la007 and tl003=la008

left join cmsmc on tl013=mc001 and mc004='1'

left join cstta on tl015=ta003 and tl016=ta004 and ta001=la001 and ta002='201108'

where tk021='y' and tk003>='20110801' and tk003<='20110831'

group by tl015 order by tl015

3、核对差异;

通过步骤一和步骤二就能检查高级成本是否算得很正确,前面2个步骤都可以通过【高级成本异常检测表】来代替检测出来成本错误。

第二部分确保分录是否抛转正确。

第一步:确认领料、退料单/入库单/委外进货/退货单抛分录正确;

1、 查询inv 中的金额;

select la006,sum(la013*la005) from invla

inner join invmb on mb001=la001

inner join cmsmc on mc001=la009

inner join cmsmq on la006=mq001

where la004>='20110801' and la004<='20110831' and

mc004=1 and mq003 like '5%'

group by la006

order by la006

2、 查询ajs中的金额;

select tb013,sum(tb007*tb004) from ajsta

inner join ajstb on ta001=tb001 and ta002=tb002

where ta006>='20110801' and ta006<='20110831' and tb005 like '5001%'

group by tb013

order by tb013

3、 查询act中的金额;

select sum(tb007*tb004),ta006 from actta

inner join acttb on ta001=tb001 and ta002=tb002

where ( 20110801')

and ( 20110831')

and ( y') and ( like '5001%')

group by ta006

4、 按照存货对账的方式对出inv-ajs-act的差异;

第二步:确保人工和制费和总账能对上;

1、 如果人工和制费对不上,那么还要确保高级成本搜集到的人工和制费是否和总账子系统中**是否相等;

SQL高级查询语句

交互式sql语句。1.1 创建数据库 unis db 日期 及其基本表 学生 课程 选课 1 建立一个 学生 表student,它由学号sno 姓名sname 性别ssex 年龄sage 所在系sdept五个属性组成,其中学号为主属性,ssex默认为 男 年龄大于0。2 建立 课程 表course,...

SQL查询语句的高级应用

一 简单查询 简单的transact sql查询只包括选择列表 from子句和where子句。它们分别说明所查询列 查询的 表或视图 以及搜索条件等。例如,下面的语句查询testtable表中姓名为 张三 的nickname字段和email字段。select nickname,email from ...

高级SQL查询语句练习

结合数据库系统原理教学的理论知识,通过实验让学生熟悉高级sql的用法,掌握sql语言的数据定义,及其他高级功能。普通pc windows系列操作系统 ibm db2 v8.1 数据库管理系统。c顾客cid cname city discnt c001 李广天津 10.00 c002 王开基北京 12...