不加条件查6万行不用1秒,加了日期查2000行要35秒(50分)

  • 主题发起人 主题发起人 LukyDee
  • 开始时间 开始时间
L

LukyDee

Unregistered / Unconfirmed
GUEST, unregistred user!
目的是查订单明细:<br>  客户表:Customers ,主键为CusID<br>&nbsp; &nbsp; &nbsp; &nbsp;订单主表:OrderMst,主键为OrderSNO<br>&nbsp; &nbsp; &nbsp; &nbsp;订单从表:OrderDtl <br>表和表之间的约束:Customers.CusID&lt;--OrderMst.CusID<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OrderMst.OrderNO&lt;--OrderDtl.OrderNO<br><br>----以下为查询语句:-----------------------------------------------------<br><br>SELECT &nbsp; &nbsp; Customers.CusID,Customers.CusName, OrderMst.OrderNO, OrderMst.OrderDate, OrderMst.CusID,<br>&nbsp;OrderDtl.ProductID<br>FROM &nbsp; &nbsp; &nbsp; &nbsp; Customers INNER JOIN<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OrderMst ON Customers.CusID = OrderMst.CusID INNER JOIN<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OrderDtl ON OrderMst.OrderNO = OrderDtl.OrderNO<br><br>执行结果6万行数据,不用1秒;<br>加了以下日期范围:<br>whereOrderMst.OrderDate between '2008-08-01' and '2008-08-10'<br><br>执行结果是:1990行,35秒<br>-------------------------------------------------------------------------------<br><br>检查数据发现,订单主表的OrderDate就没有规律,有前有后的,如:<br>OrderNO &nbsp; OrderDate <br>00001 &nbsp; &nbsp; 2008-08-01<br>00002 &nbsp; &nbsp; 2008-08-01<br>00003 &nbsp; &nbsp; 2008-07-31<br>00004 &nbsp; &nbsp; 2008-08-01<br>..........<br>00102 &nbsp; &nbsp; 2008-08-03<br>00103 &nbsp; &nbsp; 2008-08-02<br>00104 &nbsp; &nbsp; 2008-08-02<br><br>请教下优化的查询方法?
 
如你所说 OK。THKS
 
后退
顶部