select salb.fbillno '销售订单编号',case when salb.FCLOSESTATUS = 'A' then '正常'else '关闭' end '关闭状态',salb.fdate '业务日期',cusl.FNAME '客户', mat.FNUMBER '物料编码',matl.FNAME '物料名称',matl.FSPECIFICATION '规格型号', sale.FQTY '销售数量',isnull(a.scddqty,0) '生产数量',isnull(a.scrkqty,0) '入库数量',isnull(b.xsckqty,0) '出库数量',isnull(a.scrkqty,0)-isnull(b.xsckqty,0) '库存剩余数量' from T_SAL_ORDER salb left join T_SAL_ORDERENTRY sale on salb.FID = sale.FID left join T_BD_CUSTOMER_L cusl on salb.FCUSTID = cusl.FCUSTID and cusl.FLOCALEID = 2052 left join T_BD_MATERIAL mat on sale.FMATERIALID = mat.FMATERIALID left join T_BD_MATERIAL_L matl on mat.FMATERIALID = matl.FMATERIALID and matl.FLOCALEID = 2052 left join (select moe.FSaleOrderEntryId xsddentryid,sum(isnull(moe.FQTY,0)) scddqty,sum(isnull(ine.FREALQTY,0)) scrkqty from T_PRD_MO mob left join T_PRD_MOENTRY moe on mob.FID = moe.FID left join T_PRD_INSTOCKENTRY ine on moe.FENTRYID = ine.FMOENTRYID and mob.fbillno = ine.FMOBILLNO group by moe.FSaleOrderEntryId) as a on sale.FENTRYID = a.xsddentryid left join (select er.FSOEntryId xsddentryid , sum(e.FREALQTY) xsckqty from T_SAL_OUTSTOCKENTRY e left join T_SAL_OUTSTOCKENTRY_R er on e.FENTRYID = er.FENTRYID group by er.FSOEntryId) as b on sale.FENTRYID = b.xsddentryid 优化
时间: 2024-04-06 18:29:55 浏览: 79
linyanx-memory-pool-master.rar
这是一段 SQL 查询语句,用于查询销售订单的相关信息。其中包括销售订单编号、关闭状态、业务日期、客户、物料编码、物料名称、规格型号、销售数量、生产数量、入库数量、出库数量、库存剩余数量等信息。该查询语句使用了多个表的连接和聚合函数,可以进行优化。具体优化方法需要根据具体情况分析,比如优化查询语句的逻辑、增加索引等。
阅读全文