首页 新闻 会员 周边 捐助

请求高手 sql语句优化

0
悬赏园豆:10 [待解决问题]
select distinct mo.MoCode,mod.SortSeq,mod.InvCode,inv.cInvName,mod.Qty,dbo.fn_SumClum(fmbd.MoDId,2) as SMT,dbo.fn_SumClum(fmbd.MoDId,3) as DIP,dbo.fn_SumClum(fmbd.MoDId,4) as ASSY,dbo.fn_SumClum(fmbd.MoDId,5) as TEST,dbo.fn_SumClum(fmbd.MoDId,6) as PACK,
convert(varchar(100),(select MIN(CreateTime) from fc_MoRoutingBill a1 inner join fc_MoRoutingBilldetail b1 on a1.MID=b1.MID where b1.MoId=fmbd.MoId),120) as 第一报工时间,
convert(varchar(100),(select max(CreateTime) from fc_MoRoutingBill a1 inner join fc_MoRoutingBilldetail b1 on a1.MID=b1.MID where b1.MoId=fmbd.MoId),120) as 最后报工时间,
case when ISNULL(cast(dbo.fn_SumClum(fmbd.MoDId,2) as nvarchar),N'')!=N'' then (case when cast(mod.Qty as float)-cast(dbo.fn_SumClum(fmbd.MoDId,3) as float)=0 then '' else '' end) else (case when cast(mod.Qty as float)-cast(dbo.fn_SumClum(fmbd.MoDId,6) as float)=0 then '' else '' end) end as 是否结案 ,
(DATEDIFF(day,(select MIN(CreateTime) from fc_MoRoutingBill a1 inner join fc_MoRoutingBilldetail b1 on a1.MID=b1.MID where b1.MoId=fmbd.MoId),(select max(CreateTime) from fc_MoRoutingBill a1 inner join fc_MoRoutingBilldetail b1 on a1.MID=b1.MID where b1.MoId=fmbd.MoId)))-7 as 超期时间,
case when (DATEDIFF(day,(select MIN(CreateTime) from fc_MoRoutingBill a1 inner join fc_MoRoutingBilldetail b1 on a1.MID=b1.MID where b1.MoId=fmbd.MoId),(select max(CreateTime) from fc_MoRoutingBill a1 inner join fc_MoRoutingBilldetail b1 on a1.MID=b1.MID where b1.MoId=fmbd.MoId)))-7>0 then '' else '' end as 是否超期 from fc_MoRoutingBill fmb
inner join fc_MoRoutingBilldetail fmbd on fmb.Mid=fmbd.MID
inner join mom_order mo on fmbd.MoId=mo.MoId
inner join mom_orderdetail mod on fmbd.MoDId=mod.MoDId
inner join mom_morder mm on fmbd.ModId=mm.MoDId
inner join inventory inv on mod.InvCode=inv.cInvCode

 


我这个sql语句怎么优化请求高手

xiaoqingqige的主页 xiaoqingqige | 初学一级 | 园豆:7
提问于:2013-07-08 16:21
< >
分享
所有回答(4)
0

根据执行计划进行优化

dudu | 园豆:29568 (高人七级) | 2013-07-08 17:42

你好,能帮我看看我的问题吗?

http://q.cnblogs.com/q/56963/

支持(0) 反对(0) bj大海 | 园豆:56 (初学一级) | 2013-11-16 19:47
1

看来dudu在办招行信用卡啊,哈哈。根据执行计划优化,he means

+小马哥++ | 园豆:906 (小虾三级) | 2013-07-09 12:10

汗,打错字了。用招行信用卡多年了。

支持(0) 反对(0) dudu | 园豆:29568 (高人七级) | 2013-11-17 11:10
0

单单给个语句要优化是很困难的.

需要看你表的结构

数据量

dearz | 园豆:588 (小虾三级) | 2013-08-01 17:43
0

不需要查询的字段都去掉,少一些转化...总之根据sql优化准则来吧

Sunny_Lynn | 园豆:202 (菜鸟二级) | 2013-08-30 14:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册