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语句怎么优化请求高手
根据招执行计划进行优化
你好,能帮我看看我的问题吗?
http://q.cnblogs.com/q/56963/
看来dudu在办招行信用卡啊,哈哈。根据执行计划优化,he means
汗,打错字了。用招行信用卡多年了。
单单给个语句要优化是很困难的.
需要看你表的结构
数据量
不需要查询的字段都去掉,少一些转化...总之根据sql优化准则来吧