//SQL查詢代碼要如何優化,這段要十秒鐘
--查詢產品分類
SELECT PK_ID,ProdSortParentID,ProdSortName FROM dbo.ProductSort WHERE PK_ID IN(
--查詢公司產品分類ID是在產品分類產品ID
SELECT ProdSortParentID FROM dbo.ProductSort WHERE PK_ID IN(
--查詢公司產品分類ID
SELECT FK_ProductSortID FROM dbo.Shop_CompanyProductSort WHERE
FK_CompanyListID =6795 and
FK_ProductSortID IN (
--查詢該公司所有產品的分類ID
SELECT FK_ProductTypeID FROM Shop_ProductList WHERE FK_CompanyListID=6795 AND IsAudit=1 AND isDelete=0 GROUP BY FK_ProductTypeID
) GROUP BY FK_ProductSortID
)GROUP BY ProdSortParentID
)
uj5u.com熱心網友回復:
你把 Group by 去掉,這個字句嚴重影響性能。如果只是查詢某個數值在另一張表中是否存在,子查詢使用 Select top 1 ... ...
uj5u.com熱心網友回復:
建議:1.改為inner join寫法.
2.group by應可去掉.
3.注意查詢欄位和關聯欄位上應要有索引.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/99150.html
標籤:基礎類
下一篇:請教關于null
