SQL优化实例:从运行30分钟到运行只要30秒

伊人灬小爱

伊人灬小爱

2016-01-29 16:00

SQL优化实例:从运行30分钟到运行只要30秒,SQL优化实例:从运行30分钟到运行只要30秒
 以下的SQL语句在服务器需要运行长达30分钟才能完成:
SELECT     dbo.ComFlow.ComFlowCode, dbo.ComFlow.ComCode, dbo.ComFlow.CustCode, dbo.ComFlow.DepartCode, dbo.ComFlow.SaleCode,
                      dbo.ComFlow.EmpCode, dbo.ComFlow.Quantity * dbo.Commodity.ConvertRate AS Quantity, CONVERT(datetime, DATENAME(yyyy,
                      dbo.ComFlow.FlowDate) + '-' + DATENAME(mm, dbo.ComFlow.FlowDate) + '-' + DATENAME(dd, dbo.ComFlow.FlowDate)) AS FlowDate,
                      dbo.ComFlow.SalType, dbo.Employee.DepartCode AS DepartIn, dbo.Sale.DepartCode AS DepartOut,
                      dbo.ComFlow.Quantity * dbo.Commodity.TradePrice * dbo.Commodity.Discount / 100 AS Total, dbo.Department.GrpCode AS GrpCodeIn,
                      Department1.GrpCode AS GrpCodeOut
FROM         dbo.ComFlow INNER JOIN
                      dbo.Customer ON
                dbo.ComFlow.SalType IN (N'促销', N'流向退货', N'多级流向') AND dbo.ComFlow.CustCode = dbo.Customer.CustCode
                Or ComFlow_1.SalType IN (N'自然流向', N'自然流向退货') AND ComFlow_1.OutCustCode = Customer_1.CustCode
            INNER JOIN
                      dbo.CustomerRelation ON dbo.ComFlow.ComCode = dbo.CustomerRelation.ComCode AND
                      dbo.CustomerRelation.CustCode = dbo.Customer.CustCode INNER JOIN
                      dbo.Employee ON dbo.CustomerRelation.EmpCode = dbo.Employee.EmpCode INNER JOIN
                      dbo.Sale ON dbo.ComFlow.SaleCode = dbo.Sale.SaleCode INNER JOIN
                      dbo.Department ON dbo.Department.DepartCode = dbo.Employee.DepartCode INNER JOIN
                      dbo.Department AS Department1 ON Department1.DepartCode = dbo.Sale.DepartCode AND
                      dbo.Department.GrpCode < Department1.GrpCode INNER JOIN
                      dbo.Commodity ON dbo.ComFlow.ComCode = dbo.Commodity.ComCode
WHERE     (NOT (dbo.ComFlow.SalType = N'流向退货')) OR
                      (NOT (dbo.Customer.Type = N'医药公司'))
虽然说,我们使用这个语句的应用是一个BI应用,实时性要求不高,但是,我觉得没有道理会运行这么久,应该有办法优
展开更多 50%)
分享

猜你喜欢

SQL优化实例:从运行30分钟到运行只要30秒

SQLServer
SQL优化实例:从运行30分钟到运行只要30秒

SQL SERVER 优化实例:从运行30分钟到运行只要30秒

编程语言 网络编程
SQL SERVER 优化实例:从运行30分钟到运行只要30秒

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

女人6分钟30秒 让你活得更健康

孕期
女人6分钟30秒 让你活得更健康

饭后30分钟才是减肥关键

减肥 减肥方法
饭后30分钟才是减肥关键

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

居家30分钟瘦身操

减肥 健康减肥 减肥小妙招 减肥方法
居家30分钟瘦身操

30秒丰胸 从A到B就这么简单

丰胸 女人养生
30秒丰胸 从A到B就这么简单

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Photoshop教程:鼠绘非常精细的自动铅笔图标

Photoshop教程:鼠绘非常精细的自动铅笔图标

SQL Server应用程序高级SQL注入(下)

SQL Server应用程序高级SQL注入(下)
下拉加载更多内容 ↓