所以我知道基本的SQL,但我不是专家。我维护的系统似乎每隔几天就会放慢一点,并且我认为它是来自某个地方的错误查询。SQL查询优化 - 降低服务器效率
从我所知道的情况来看,我已经将问题缩小到了一两页。以下是我认为导致问题的页面上的查询。
select a.s_purchase_order as order_id, a.order_type, a.nobackorder, a.order_note, a.note, a.rqst_dlvry_date, b.customer_name ,c.store_name,(c.store_name + ',' + isnull(c.address1 + ',', ' ') + isnull(c.city + ',', ' ') + isnull(c.state_cd+ ',', ' ') + isnull(c.zipcode, ' ')) as store_info, d.supplier_account
from VW_CustomerOrder a, Customer b, Store c, eligible_supplier d
where a.customer = c.customer
and a.store = c.store
and a.customer = b.customer
and c.customer *= d.customer
and c.store *= d.store
and a.supplier *= d.supplier
and a.purchase_order = @order_id
and a.customer = @customer_id
and [email protected]_id
and a.supplier = @supplier_id
是否有明显的东西会很慢或导致系统随着时间变慢?
如果没有关于表格的更多信息,您甚至可能无法回答。如果是的话,让我知道,我可以张贴更多的细节。
谢谢!
做你的加入在FROM子句(如下面的答案)不在where子句中,它提高了可读性。另外,你使用的是什么DBMS? MySQL的? SQL Server?其他? – Ghost 2012-08-02 17:23:12
@Yaroslav不要将自己的语法偏好强加于他人。您的大写SQL关键字不比小写关键字更正确,并且它们看起来(在我看来)是可怕的。 – meagar 2012-08-02 18:53:44
谢谢你们,这是一个好主意,但我现在得到一个错误。感谢您的帮助 – fullOfQuestions 2012-08-02 19:40:50