会员名称: 登录密码: (找回密码) 登录 会员注册

分类

问题
上个主题 下个主题
主题:求助SQL语句求合计
avatar
灵魂大师
IT 行业
Ta擅长:
K/3 BOS(29),SOA(18) 本周回答(0),本月回答(0)
发贴时间:2007-9-11 10:48:03   完成时间: 2007-9-12 17:18:24
赠分:25      回答:3   已经到期    
语句如下:
select distinct t1.fbillno as '订单号',
t2.fentryid as '订单分录号',
t3.fnumber as '物料编码',
t3.fname as '物料名称',
t3.fmodel as '规格型号',
t2.fqty as '订单数量',
t2.fdate as '纳期',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then sum(t5.fqty) else 0 end as '合计出货量',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then max(t4.fdate) else null end as '实际最晚交期',
case when sum(t5.fqty)>=t2.fqty then 1 else 0 end as '满足订单'
FROM seorder t1 INNER JOIN seorderentry t2 on t1.finterid=t2.finterid
INNER JOIN t_icitem t3 ON t3.fitemid=t2.fitemid
LEFT JOIN icstockbillentry t5 ON t5.forderinterid=t2.finterid and t5.forderentryid=t2.fentryid
LEFT JOIN icstockbill t4 ON t4.finterid=t5.finterid
WHERE t1.FDate>='********'
and t1.FDate
GROUP BY t1.fbillno,t4.ftrantype,t2.fentryid,t2.fitemid,t3.fname,t3.fmodel,t2.fqty,t2.fdate,t3.fnumber,t5.forderentryid,t5.forderentryid,t5.forderinterid,t2.finterid
ORDER BY t1.fbillno

目前已根据出货时间和出货数量进行了订单分录是否满足订单的判断,接下来还需要判断如果所有订单分录都满足订单,则该订单满足。
现在是想根据t1.fbillno进行'满足订单'字段的统计,然后得出满足的订单占总订单数的比率,并能用图表显示。
希望各位高手能够赐教,万分感谢!
修改时间:2007-9-11 10:55:18
修改时间:2007-9-11 10:55:43
avatar
好望角
IT 行业
Ta擅长:
金蝶K/3(88),金蝶KIS(30) 本周回答(0),本月回答(0)
回答时间:2007-9-11 16:22:13
用这个方法,先到查询分析器执行下面这段代码:
create proc newnew
@begdate datetime,
@enddate datetime
as
set nocount on
create table #aa(
订单号 varchar(255),
订单分录号 int,
物料编码 varchar(255),
物料名称 varchar(255),
规格型号 varchar(255),
订单数量 decimal(18,2),
纳期 datetime,
合计出货量 decimal(18,2),
实际最晚交期 datetime,
满足订单 decimal(18,10)
)
insert into #aa(订单号,订单分录号,物料编码,物料名称,规格型号,订单数量,纳期,合计出货量,实际最晚交期,满足订单)
select distinct t1.fbillno as '订单号',
t2.fentryid as '订单分录号',
t3.fnumber as '物料编码',
t3.fname as '物料名称',
t3.fmodel as '规格型号',
t2.fqty as '订单数量',
t2.fdate as '纳期',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then sum(t5.fqty) else 0 end as '合计出货量',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then max(t4.fdate) else null end as '实际最晚交期',
case when sum(t5.fqty)>=t2.fqty then 1.000 else 0.000 end as '满足订单'
FROM seorder t1 INNER JOIN seorderentry t2 on t1.finterid=t2.finterid
INNER JOIN t_icitem t3 ON t3.fitemid=t2.fitemid
LEFT JOIN icstockbillentry t5 ON t5.forderinterid=t2.finterid and t5.forderentryid=t2.fentryid
LEFT JOIN icstockbill t4 ON t4.finterid=t5.finterid
WHERE t1.FDate>=@begdate
and t1.FDate GROUP BY t1.fbillno,t4.ftrantype,t2.fentryid,t2.fitemid,t3.fname,t3.fmodel,t2.fqty,t2.fdate,t3.fnumber,t5.forderentryid,t5.forderentryid,t5.forderinterid,t2.finterid
order by t1.fbillno

insert into #aa (订单号,满足订单)
select '完成百分比',round(convert(decimal(18,10),sum(满足订单))/convert(decimal(18,10),count(*)),3) from
(select distinct t1.fbillno as '订单号',
t2.fentryid as '订单分录号',
t3.fnumber as '物料编码',
t3.fname as '物料名称',
t3.fmodel as '规格型号',
t2.fqty as '订单数量',
t2.fdate as '纳期',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then sum(t5.fqty) else 0 end as '合计出货量',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then max(t4.fdate) else null end as '实际最晚交期',
case when sum(t5.fqty)>=t2.fqty then 1 else 0 end as '满足订单'
FROM seorder t1 INNER JOIN seorderentry t2 on t1.finterid=t2.finterid
INNER JOIN t_icitem t3 ON t3.fitemid=t2.fitemid
LEFT JOIN icstockbillentry t5 ON t5.forderinterid=t2.finterid and t5.forderentryid=t2.fentryid
LEFT JOIN icstockbill t4 ON t4.finterid=t5.finterid
WHERE t1.FDate>=@begdate
and t1.FDate GROUP BY t1.fbillno,t4.ftrantype,t2.fentryid,t2.fitemid,t3.fname,t3.fmodel,t2.fqty,t2.fdate,t3.fnumber,t5.forderentryid,t5.forderentryid,t5.forderinterid,t2.finterid ) a

select * from #aa order by 订单号
drop table #aa


命令成功完成后,到查询分析工具或BOS里面新建SQL报表,输入: newnew '********','########'

经过这个动作后应该可以了.
修改时间:2007-9-11 16:26:58
稳健发展,追求卓越。
发文者评价: (共获积分:25
  非常感谢,不但帮我解决了问题,而且对我处理类似问题也提供了解决思路,谢谢了
网友评价: 75%       25%     (目前有 4 人评价)
你的评价:
其他回答
avatar
lwlghost
IT 行业
Ta擅长:
金蝶K/3(15),金蝶KIS(12) 本周回答(0),本月回答(0)
回答时间:2007-9-11 11:22:39
建议你做个存储过程,做一个临时表,
把这些数据写入表中,然后做表的统计




经常不在线,点击这里给我发消息
lwlghost@hotmail.com MSN在线稳定
 
avatar
好望角
IT 行业
Ta擅长:
金蝶K/3(88),金蝶KIS(30) 本周回答(0),本月回答(0)
回答时间:2007-9-11 12:01:18
先来这个吧,看看是不是你要的:
select distinct t1.fbillno as '订单号',
t2.fentryid as '订单分录号',
t3.fnumber as '物料编码',
t3.fname as '物料名称',
t3.fmodel as '规格型号',
t2.fqty as '订单数量',
t2.fdate as '纳期',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then sum(t5.fqty) else 0 end as '合计出货量',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then max(t4.fdate) else null end as '实际最晚交期',
case when sum(t5.fqty)>=t2.fqty then 1.000 else 0.000 end as '满足订单'
into #aa
FROM seorder t1 INNER JOIN seorderentry t2 on t1.finterid=t2.finterid
INNER JOIN t_icitem t3 ON t3.fitemid=t2.fitemid
LEFT JOIN icstockbillentry t5 ON t5.forderinterid=t2.finterid and t5.forderentryid=t2.fentryid
LEFT JOIN icstockbill t4 ON t4.finterid=t5.finterid
WHERE t1.FDate>='********'
and t1.FDate (小于等于八个井号加引号,奇怪,竟然显示不出来)
GROUP BY t1.fbillno,t4.ftrantype,t2.fentryid,t2.fitemid,t3.fname,t3.fmodel,t2.fqty,t2.fdate,t3.fnumber,t5.forderentryid,t5.forderentryid,t5.forderinterid,t2.finterid
order by t1.fbillno

insert into #aa (订单号,满足订单)
select '完成百分比',round(convert(decimal(18,10),sum(满足订单))/convert(decimal(18,10),count(*)),3) from
(select distinct t1.fbillno as '订单号',
t2.fentryid as '订单分录号',
t3.fnumber as '物料编码',
t3.fname as '物料名称',
t3.fmodel as '规格型号',
t2.fqty as '订单数量',
t2.fdate as '纳期',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then sum(t5.fqty) else 0 end as '合计出货量',
case when t4.ftrantype='21' and t5.forderinterid=t2.finterid and t2.fentryid=t5.forderentryid then max(t4.fdate) else null end as '实际最晚交期',
case when sum(t5.fqty)>=t2.fqty then 1 else 0 end as '满足订单'
FROM seorder t1 INNER JOIN seorderentry t2 on t1.finterid=t2.finterid
INNER JOIN t_icitem t3 ON t3.fitemid=t2.fitemid
LEFT JOIN icstockbillentry t5 ON t5.forderinterid=t2.finterid and t5.forderentryid=t2.fentryid
LEFT JOIN icstockbill t4 ON t4.finterid=t5.finterid
WHERE t1.FDate>='********'
and t1.FDate (小于等于八个井号加引号,奇怪,竟然显示不出来)

GROUP BY t1.fbillno,t4.ftrantype,t2.fentryid,t2.fitemid,t3.fname,t3.fmodel,t2.fqty,t2.fdate,t3.fnumber,t5.forderentryid,t5.forderentryid,t5.forderinterid,t2.finterid ) a

select * from #aa order by 订单号
drop table #aa
修改时间:2007-9-11 12:19:52
修改时间:2007-9-11 12:21:38
修改时间:2007-9-11 12:23:36
修改时间:2007-9-11 12:25:07
稳健发展,追求卓越。
View as RSS news feed in XML
© 2008 金蝶国际软件集团 版权所有  Version:3.2.2008.27643 页面时间:113.9228Ms